paste command

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.

Any help would be appreciated.

:slight_smile: 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
:slight_smile:

a="Mary had a little"
b="lamb"
c="$a $b"
echo $c
echo $c >>third.file

I wonder if you have tried the join command.
see the man for exact syntax, but I'am sure that it can help

$ 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

pls try this...
for i in `cat file1`
do
b=`grep $i file2`
if [ $? -eq 0 ]
then
echo $b >> tt
fi
done