Awk - Multiline matching, printing filename and match -
Awk - Multiline matching, printing filename and match -
i have next awk command:
awk -v rs=! -v ors= '/abc/ && /def/ {print filename;}' files
this looks in each file in files, separates each record in file '!', , matches record 'abc' , 'def'. above code print name of file. if remove {print filename}
print whole record if matched.
a file like:
abc1 bce bcd def ! abc2 bce def !
i want print out filename , line matches 'abc'. example:
file1 abc1 file2 abc2 abc3
how can go this?
awk 'fnr==1{print filename} /abc/' file1 file2
the fnr
field set 1
new file read. fnr==1
true, @ first line of each input file, action performed print filename
print file1
, file2
/abc/
match lines containing abc
since no action specified, default beingness print entire record ($0
) performed. similar writing /abc/{print $0}
file1 abc1 file2 abc2 abc3
awk
Comments
Post a Comment