1758560 Members
2102 Online
108872 Solutions
New Discussion

Re: File interrogation

 
SOLVED
Go to solution
Sridhar Bhaskarla
Honored Contributor
Solution

Re: File interrogation

Hi Cathy,

Here is the modified script. Now do not run the individual commands as you may run into syntax issues. Just modify ABCXXXX.txt to match your filename and then run the script as it is. This will generate two files. ABCXXXX.txt.good and ABCXXXX.txt.bad.

----copy below---

#!/usr/bin/ksh
FILE=ABC1390.txt
MYNAME=$(echo $FILE|awk -F "." '{print $1}'|sed 's/ABC//g')

awk -v STR="$MYNAME" -F "," '$2 == STR {print $0}' $FILE > $FILE.good
awk -v STR="$MYNAME" -F "," '$2 != STR {print $0}' $FILE > $FILE.bad

----till here---

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
cbres00
Frequent Advisor

Re: File interrogation

Hi Sri.
I finally got it to work but only by using nawk rather than awk.

Thanks for your valuable assistance. Enjoy the points!

Cathy
Life is too short not to have fun every single day