net
January 9, 2009, 12:31am
1
I am trying to find for the pattern in first 5 bytes of every line in a text file and then generate a new file with the pattern found.
Example: expected pattern is '-' to be serached in first 5 bytes of file only.
Input File
ab-cd jan-09
ddddd jan09
cc-ww jan09
dsgdq jan-09
Output Required :
ab-cd jan-09
cc-ww jan09
Can anyone suggest how to achieve this using unix command or script?
skar_a
January 9, 2009, 1:03am
2
net:
I am trying to find for the pattern in first 5 bytes of every line in a text file and then generate a new file with the pattern found.
Example: expected pattern is '-' to be serached in first 5 bytes of file only.
Input File
ab-cd jan-09
ddddd jan09
cc-ww jan09
dsgdq jan-09
Output Required :
ab-cd jan-09
cc-ww jan09
Can anyone suggest how to achieve this using unix command or script?
You can use grep to search for lines not having - in its first five positions and use -v option to print all other lines(i.e lines having - in first five chars)
$ cat t
ab-cd jan-09
ddddd jan09
cc-ww jan09
dsgdq jan-09
$ grep -v '^[^-]\{5\}' t
ab-cd jan-09
cc-ww jan09
$
net
January 9, 2009, 1:35am
3
Hey Thanks This is working.