I wonder if any body can help me with a command i am struggling with. I have a file with around 400 lines in, in a program i have it pulls out each line at a time so that data from the line can be cross referenced with another file. If it finds a match it pulls out a ocde from the second file, this then needs to be put on the end of the first line.
Fo example:
I have a line that says Mary had a little
In the second file it finds this and pulls out the code lamb
The lamb then needs to be put on the end of the first line to make Mary had a little lamb. Then this line needs to be added to a new file.
I have tried the paste command but this does not work as it will only paste the out put of one file to the other. I want to paste variables of data together and then put it in a new file.
I know this may sound confusing but i do not know how to explain it any better.
i am not sure what your're trying to say completely but i have tried a few variation with the paste command and it should work..
use paste command:
paste file1 file2 ; the you can use ;
awk -F '{printf "%-15s%3s ", $1, $2}EX,.
you can put a variation on the strings in the awk command using the printf flags and that should give you enough to play with to do pretty much anything with pasted files and strings..
hope that helps.. also I am not sure about this .. but I think you can actually pipe the awk command to paste command to make one command line operation;;
paste file1 file2 | awk -F etc etc > new.file
depending on what kind of text you havein the files the -F option has to have the right field seperator'' EX,. -F '[\t]' would give a filed seperator that is a tab.. and -F: a colon etc..
moxxx68
$ echo "Mary had a little" > file1
$ echo "Mary had a little lamb" > file2
$ grep -f file1 file2
Mary had a little lamb
$ awk 'FNR==NR{d=$NF;sub(FS d "$","");a[$0]=d;next};{print $0, a[$0]}' file2 file1
Mary had a little lamb