Maybe some UNIX guru has a more elegant way than this. I do a lot of shell scripting. So the easiest way to do this was with a script. I am using korn shell for this. Most U2 people I know avoid shell scripts.
I wrote a quick somewhat generic script to do it called rod.test. You give it the two file names that you are combining. Here is the script: # cat rod.test #!/usr/bin/ksh -x #script to combine and sort two unix files script=`basename $0` newfile="newfile" if [ $# -lt 2 ]; then echo "\n Usage: ${script}: file1 file 2\n" exit 1 fi cat $1 | awk ' { print "file1*" $1 } ' > $newfile cat $2 | awk ' { print "file2*" $1 } '>> $newfile sort $newfile -t* -k2 The -x in line one will run it in debug mode so you can see each line as it executes: ./rod.test file1 file2 + + basename ./rod.test script=rod.test + newfile=newfile + [ 2 -lt 2 ] + awk { print "file1*" $1 } + cat file1 + 1> newfile + awk { print "file2*" $1 } + cat file2 + 1>> newfile + sort newfile -t* -k2 file1*line1 file2*line1 file1*line2 file2*line2 file1*line3 file2*line3 If you want to put the output in a third file, add sortedfile to the last line: sort newfile -t* -k2 > sortedfile Hope this helps. Also hope I understand what you wanted. If not let me know. -Rod -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Tuesday, June 19, 2007 4:37 PM To: u2-users@listserver.u2ug.org Subject: [U2] Unix cat help Hi all, Hopefully there is a way to do this... I have 2 unix flat files that I want to merge into 1 file. I know that I can do something like "cat file1 file2 | sort -o newfile". The problem is that once I have newfile loaded, I need to know where each line in newfile came from. I am hoping that unix has something similar to the REUSE() function so I can prefix each line with the filename. Here is an example of what I would like to get done. before... /sws/scott/temp: pg file1 line1 line1 line1 line1 line1 line2 line2 line2 line2 line2 line3 line3 line3 line3 line3 /sws/scott/temp: pg file2 line1 line1 line1 line1 line1 line2 line2 line2 line2 line2 line3 line3 line3 line3 line3 after... /sws/scott/temp: pg newfile file1*line1 line1 line1 line1 line1 file2*line1 line1 line1 line1 line1 file1*line2 line2 line2 line2 line2 file2*line2 line2 line2 line2 line2 file1*line3 line3 line3 line3 line3 file2*line3 line3 line3 line3 line3 Thanks in advance for any thoughts you may have. Scott Thompson ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/