Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help writing a UNIX script to merge tow files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need help with merging two files with matching data. I know very little about writing scripts so please answer at the most granular level if possible. All help will be greatly appreciated.
I am trying to write a script that will take two files (A&B) and extract the needed and matching data to a third file(C).
File A contains detail data with no line numbers.
File B contains the line number of the detail line in file A in the second pipe delimited field that has corresponding information.
The result I am looking for is a file C that contains both file A and file B information on for the matching lines only.

This is what I think I need to do, but I don’t know how to do it.

Have the script receive both file names.
Write a line number to each of the lines in the A file. (Use the wr command maybe?)
Do a grep on the B file, so it contains only the lines that have “Error” in the line.
Use the join command to match the line number that I have added in the A file to the matching line number in the second pipe delimited field of the B file to create a C file that contains the line information that has been combined from both files.

Once again if you could break it down to the lines in the script that would be great. I know very little about writing scripts and using UNIX command.
Thanks for your help.
Kevin
 
For the kind of data manipulation you are talking about, the best UNIX tool to use is "awk". Awk works very similar to C programming and is one of the most powerful data manipulation tools I have ever seen. Do you have any programming experience outside of UNIX? To start with, you should do a man of the "awk" command and read through it.

If your intent is to get someone from this forum to help write the script for you, what you should do is post a sample of what files A and B look like, and what file C should look like.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top