Thread: How to process each output from grep

  1. #1
    Registered User
    Join Date
    Nov 2011
    Location
    Buea, Cameroon
    Posts
    197

    How to process each output from grep

    I'm working on this shell script to process the each output from grep by searching each regexp from file1 and using each matching regexp and searching file2 for a matching line and using awk to delete

    Code:
    #Here is my code
    #!bin/sh
    
    regexp="[a-z]*.[a-z][,$]+"
    
    file1=$1
    file2=$2
    
    #this searches all matching regexp in file1
    grep -i -o -E "$regexp" $file1 #how to assign each output to$str was thinking of arrays,here but it'll be long 
    
    #Problems is using each output from grep lets say $str
    
    #next part searching file 2 for $str and deleting each matching line
    line=$(grep -o -i "$str" $file2)
    
    #delete line
     sed '/$line/d' $file2

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    I'm guessing you may want to process the output from grep line by line? Then you could use this kind of loop

    Code:
    grep -iE "$regexp" "$file1" | \
    while read
    do
        echo "$REPLY"
    done
    The while loop will execute once per line of output from the piped command. The read command puts the read line into the REPLY environment variable. You could then put in that block whatever you'd like to do

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting Output from an external process
    By radroach in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2005, 07:53 PM
  2. Controling a process's audio output
    By Gravedigga in forum Windows Programming
    Replies: 0
    Last Post: 05-13-2005, 10:44 AM
  3. Grep Last Pattern Output
    By cfriend in forum Linux Programming
    Replies: 1
    Last Post: 09-18-2004, 10:14 AM
  4. how to get output of a process?
    By dkt in forum C Programming
    Replies: 5
    Last Post: 01-10-2003, 12:20 PM
  5. how to get the output of a non-stop process?
    By dkt in forum C Programming
    Replies: 1
    Last Post: 04-27-2002, 11:18 AM