> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]

[snip]

> 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

Can you put the originating file at the end of the line?  That would
allow you to alter the line prior to sorting and still have it sort
correctly.  I think the following shell script would do it:

#!/bin/sh
{
        for LINE in `cat file1`;
        do
                echo "$LINE*file1"
        done

        for LINE in `cat file2`;
        do
                echo "$LINE*file2"
        done
} | sort -o newfile

This is the only way I can think of that you'd be able to both sort the
way you want and retain the information about which file the line came
from.  If the file name has to be at the beginning, you could probably
run this output through something like sed, awk, and/or cut to rearange
each line by using "*" as a delimiter.

-John
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to