darwin
darwin

Reputation: 25

deleting lines from text files which are in another file

This is the continuation of my previous question. deleting lines from text files based on the last character which are in another file using awk or sed

I am trying to get the following output using my previous example? I am new to awk.Please give suggestions.

 csh    1      A   1      27.704   6.347   
 csh    2      A   1      28.832   5.553
 csh    3      A   1      28.324   4.589
 csh    6      A   1      28.378   4.899

Upvotes: 2

Views: 312

Answers (3)

anubhava
anubhava

Reputation: 786339

Taking some code from previous answers, you can use this code:

while read word; do
    if [[ $word =~ ^(....)(.)$ ]]; then
        filename="yy/${BASH_REMATCH[1]}.txt"
        letter=${BASH_REMATCH[2]}
        [[ -f $filename ]] && sed -i.bak -n "/^ *csh.*$letter/p" $filename
    fi
done < xx.txt

Upvotes: 1

potong
potong

Reputation: 58578

This might work for you:

sed '/^ *chs.*A/!d' file

Upvotes: 1

Dennis Williamson
Dennis Williamson

Reputation: 360703

You need to carry forward any information from the previous question that provides specifications for this one.

This may work for you:

awk '$3 == "A"' inputfile

You can replace "inputfile" with a glob, perhaps *, in order to process multiple files as if they were cated together.

Without having a clearer indication of how you want the multiple files processed, that's the best I can do.

Upvotes: 1

Related Questions