开发者

sed + match the first word in line and the second word that begin with abc

开发者 https://www.devze.com 2023-01-14 04:46 出处:网络
How to match all lines that begins with word ADDRESS and the second string start with abc characters.

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 synt开发者_StackOverflow社区ax 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)


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

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


Why not just do:

grep '^ADDRESS abc' input_file


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号