Tuesday, March 4, 2008
Delete the line where pattern is found - AWK
The sample file is like this:
$ cat myfile.out
CAN1:23:1970:2006:A
CAN5:45:1999:2007:D
CAN2:14:2006:2008:A
CAN3:43:1982:2000:E
Purpose:
Delete the lines whose (4th field is either 2006 or 2000) or (3rd field is 1999)
Note: we can't use "grep -v" here, as the search pattern "2206" is 3rd filed in 3rd line, but we are interested in 2006 in 4th field.
$ awk -F ":" '$4 ~ /2006|2000/ || $3 ~ 1999 {next}1' myfile.out
CAN2:14:2006:2008:A
or
$ awk -F ":" '$4 !~ /2006|2000/ && $3 !~ /1999/ ' myfile.out
CAN2:14:2006:2008:A
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
No comments:
Post a Comment