bash - Find string from a file to another file in shell script -
i new shell scripting. wanna know how can obtain result wanted following:
i have 2 files (file_a , file_b)
file_a contains:
09228606355,71295939,1,http://sun.net.ph/043xafj.xml,01000001c123000d30 09228505450,71295857,1,http://sun.net.ph/004xafk.xml,01000001c123000d30
file_b contains:
http://sun.net.ph/161ybfq.xml ,9220002354016,93111 http://sun.net.ph/004xafk.xml ,9220002354074,93111
if url (4th field) in file_a present in file_b, out be:
09228505450,71295857,1,http://sun.net.ph/004xafk.xml,01000001c123000d30,9220002354074,93111
it display whole line in file_a , added 2nd , 3rd field of file_b.
i hope question clear. thank you.
this might work (gnu sed):
sed -r 's/^\s*(\s+)\s*,(.*)/\\#^([^,]*,){3}\1#s#$#,\2#p/' fileb | sed -nrf - filea
this builds sed script fileb , runs against filea. second sed script run in silent
mode , lines match sed script printed out.
Comments
Post a Comment