Results 1 to 10 of 10
Hi I need to merge two files using awk or any scripting tool.
The requirement is like this
File A is like this:
EI3171280 38640658501 NENN2005-12-129999-12-312005-12-12HALL NANCY 344 CHENEY HIGHWAY ...
- 11-23-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
Merging two files
Hi I need to merge two files using awk or any scripting tool.
The requirement is like this
File A is like this:
EI3171280 38640658501 NENN2005-12-129999-12-312005-12-12HALL NANCY 344 CHENEY HIGHWAY TITUSVILLE FL32780-0000 N 1-1192515160
PI95000M 23326685801 NENN2005-12-121924-02-172005-12-12POLING EARL W 2600-26TH AVE PARKERSBURG WV26101-0000 N 1-1192669087
EI3212756 58007867001 NSNN2005-12-121936-09-192005-12-12CRUZ AIDA P.O. BOX 1295 KINGSHILL,ST. C VI00851 N 1-1193006037
EI3210432 05128396601 NENN2005-12-121933-04-132005-12-12NERKO ELEANORE 60-16-76TH ST ELMHURST NY11373-2417 N 1-1192833610
EI3206592 23560778101 NENN2005-12-121941-08-312005-12-12SLAUGHTER CARL G 452 EAST FAIRLAWN DRIVE COVINGTON VA24426-0000 N 1-1192854020
PI25802 04738568501 NENN2005-12-121947-09-272005-12-12VLECIDES CONSTANTINE 27 WIND HILL WAY HOLMDEL NJ07733-1134 N 1-1192966250
EI3209792 43224032301 NENN2005-12-121916-01-192005-12-12SIMPSON LOUISE E 1102 DALINE SPRINGDALE AR72764-0000 N 1-1192968873
NI2429593 76420731101 NSNN2005-12-121974-01-282005-12-12RAMIREZ PEDRO 414 W PENNSYLVANIA TUCSON AZ85714 N 1-1193264262
EI3309644 61719151504 NSNN2005-12-121999-02-232005-12-12SANDOVAL ANDRES 1727 ROSE AVE SANTA ROSA CA95407-0000 N 1-1193559416
EI3308928 43065868602 NENN2005-12-121968-03-022005-12-12MILLS SR JOHN D 906 HOGAN DR MURFREESBORO TN37128-0000 N 1-1193399232
EI3308972 46825707401 NENN2005-12-121985-03-082005-12-12LEFEVRE STEPHANIE 17175 WALNUT LANE SPIRIT LAKE IA51360-0000 N 1-1193538259
999999 ICARE 2005-12-13 000000011
Now file B is also similar like that.
The highlighted items in red indicate that there are eleven records.
I just need to merge file A with file A once again. without checking any duplicate and finally increase the count of records to 22.
Can anybody please help me with this??
Thanks in advanc e.
Ratul
- 11-23-2007 #2
If you haven't read any of these man pages, I would urge you to do this at the command line:
If you do not have these man pages on your system, make these google searches:Code:man bash man sed man awk man perl
Don't read each of them from beginning to end; you'll get spots in front of your eyes. Just scan each man page to get a feel for what's going on.Code:Linux man bash Linux man sed Linux man awk Linux man perl
Then make these google searchs and follow your nose to enlightenment:
Once you've done this, build your solution. Don't try to write the whole thing and test it; do it in small steps, testing as you go.Code:bash tutorial sed tutorial awk tutorial perl tutorial
When you have specific questions about why something doesn't work, come back to us, post the code you have so far, and ask your specific question.
Good luck!--
Bill
Old age and treachery will overcome youth and skill.
- 11-23-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
thanks buddy.. Actually am totally new to all these..havent worked on Unix before..thanks again..let me check..I'll get back to you for sure!!
- 11-23-2007 #4Just Joined!
- Join Date
- Nov 2007
- Posts
- 2
Col1=`grep "ICARE" test.txt |awk '{print $1}'`
Col2=`grep "ICARE" test.txt |awk '{print $2}'`
Col3=`grep "ICARE" test.txt |awk '{print $3}'`
count=`grep "ICARE" test.txt |awk '{printf("%09d",$4*2)}'`
grep "NN2005" test.txt >>merged.txt
grep "NN2005" test.txt >>merged.txt
echo $Col1 $Col2 $Col3 $count >>merged.txt
#echo $Col1 $Col2 $Col3 $count
- 11-23-2007 #5
sahrawat_amit's solution will work, with three reservations:
- venommaker didn't specify the order in which he wanted the lines in the merged files. There's a good chance that the order used in this solution is not exactly what he had in mind.
- This solution, as written exactly, will provide false results if you run it twice in a row with nothing else done in between. Try it!
- venommaker will learn far more by constructing a solution himself and coming to us with specific problems. (And, judging from the tone of his response, he's open to walking this path to enlightenment.)
--
Bill
Old age and treachery will overcome youth and skill.
- 11-24-2007 #6Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
- 11-24-2007 #7Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
guys i feel so thankful to all of you...let me try them out.. am working on them...am a little fool with Unix..its totally new to me..so whatever you say..I would take it for granted..
- 11-24-2007 #8Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
hi Wje_if, I'd love to move towards the enlightenment but the problem is that I need to deliver this code at the earliest and I'm really running short of time. So in that way I'm in a little hurry..
Anyways a couple of information that I would want to provide is:
1. Both files are of same pattern but could be of different lengths.
2.There is no as such order of merging. After the first file is piped to the output, the second file could be merged.
3.And once these files are processed, they would be deleted from the Unix box and then I'll be using Java to go forward.
Please advise!!
Thanks again for your cooperation
- 11-24-2007 #9
I'm in a bit of a hurry, too, but show us your script and tell us how it misbehaves and I'm sure someone will step forward. :)
--
Bill
Old age and treachery will overcome youth and skill.
- 12-19-2007 #10Just Joined!
- Join Date
- Nov 2007
- Posts
- 5
hi everyone.. this solution works well for me except for a couple of things pointed out by you guys in the previous post.
Col1=`grep "ICARE" test.txt |awk '{print $1}'`
Col2=`grep "ICARE" test.txt |awk '{print $2}'`
Col3=`grep "ICARE" test.txt |awk '{print $3}'`
count=`grep "ICARE" test.txt |awk '{printf("%09d",$4*2)}'`
grep "NN2005" test.txt >>merged.txt
grep "NN2005" test.txt >>merged.txt
echo $Col1 $Col2 $Col3 $count >>merged.txt
#echo $Col1 $Col2 $Col3 $count
Problems are:
This solution, as written exactly, will provide false results if you run it twice in a row with nothing else done in between.. Pointed by wje_If.
how do i fix this??
moreover the number of lines in two different files can be different.. how to fix that problem??


Reply With Quote
