0

I am new to shell scripting. Just wanna know how can I obtain the result I wanted with the following:

I have two files (FILE_A and 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 the URL (4th field) in FILE_A is present in FILE_B, the out will be:

  09228505450,71295857,1,http://sun.net.ph/004xafk.xml,01000001C123000D30,9220002354074,93111

It will display the whole line in FILE_A and added 2nd and 3rd field of FILE_B.

I hope my question is clear. Thank you.

1

2 Answers 2

1

This might work for you (GNU sed):

sed -r 's/^\s*(\S+)\s*,(.*)/\\#^([^,]*,){3}\1#s#$#,\2#p/' fileB | sed -nrf - fileA

This builds a sed script from fileB and runs it against fileA. The second sed script is run in silent mode and only those lines that match the sed script are printed out.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

paste -d , A B  | awk -F , '{if ($4==$6) print "match", $1,$2,$3,$4,$5,$7,$8;}'

I removed the spaces in your file B for the $4==$6 to work.

I use paste to create a composite line using , as the delimiter to get a line with , . I then use awk comparison to check the URLs from both files and if a match is found I print all the fields you care about.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.