cjb123
asked on
sed / awk / grep on files in directory
Hello:
I need some help please. I need a ksh script that will perform some rather basic sed/awk grep commands.
I have a directory full of .txt files. Each file in this directory needs to undergo a treatment.
(learned from earlier EE posting)
1. sed -e 's/~/~\n/g' $file1 > $file1.$$
I'm interested in lines starting with "W12" within these files. When I grep for that pattern in each .txt file, it produces STANDARDIZED output like this. (Delimiter will always be a '*' and position is fixed.)
W12*CL**18****VN*4921427~
W12*CL**3****VN*4921537~
W12*CL**4****VN*4931037~
W12*CS**2****VN*5057600~
W12*CS**5****VN*5057604~
2. I'd like to see the filename _AND_ line number where the grep match took place
3. Also need to count the # of times 'CL' and 'CS' appear in that output shown above.
4. Need to put a tab between the 5th and 6th char in the 7 digit integer shown in lines above.
5. Need to e-mail the ultimate output to a list of users
Thank you very much.
ASKER
Sunnycoder:
thanks for quick reply. Would you please help me get the FILENAME and LINE NUMBER from the grep commands where pattern "W12" isfound? Thank you.
thanks for quick reply. Would you please help me get the FILENAME and LINE NUMBER from the grep commands where pattern "W12" isfound? Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
grep -n ^W12 $file1.$$
CL_count=`grep -n ^W12 $file1.$$ | grep CL | wc -l`
CS_count=`grep -n ^W12 $file1.$$ | grep CS | wc -l`
#4. Need to put a tab between the 5th and 6th char in the 7 digit integer shown in lines above.
grep -n ^W12 $file1.$$ | sed 's/\(.*\*\)\(.....\)\(..\)
#5. Need to e-mail the ultimate output to a list of users
mutt -a final_out.txt -s "the output" receiver@domain.com