views:

41

answers:

3

How to match all lines that begins with word ADDRESS and the second string start with abc characters.

remark - ( I need to combine the sed syntax in my shell script)

for example

 more file

 ADDRESS abc1a (match)
 ADDRESS abc1b (match)
 ADDRESS acb1a (will not match)
 ADRESS  abc   (will not match)
 ADDRESS abc2a (will match)
 ADDRES  abc1a (will not match)
 ADDRESS ab    (will not match)
+1  A: 

Why not just do:

grep '^ADDRESS abc' input_file
codaddict
+1  A: 
sed -n '/^ADDRESS[ \t]*abc/p' file

I suggest you show us your code next time since i believe you are quite familiar with ksh/sed/awk etc already.

ghostdog74
sed -n '/[ \t]*ADDRESS[ \t]*abc/p' file ( i correct this if I have space in the line between begin of line to ADDRESS)
lidia
you probably want `\+` instead of `*` for the space pattern to ensure at least one
glenn jackman
+1  A: 

Not a sed answer, but this is a clear translation of your requirements:

awk '$1 == "ADDRESS" && substr($2,0,3) == "abc"'
glenn jackman