paste command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users paste command
# 1  
Old 10-01-2004
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.
# 2  
Old 10-03-2004
CPU & Memory hope this helps...

Smilie 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
Smilie

Last edited by moxxx68; 10-03-2004 at 03:02 AM..
# 3  
Old 10-03-2004
a="Mary had a little"
b="lamb"
c="$a $b"
echo $c
echo $c >>third.file
# 4  
Old 03-03-2005
I wonder if you have tried the join command.
see the man for exact syntax, but I'am sure that it can help
# 5  
Old 03-03-2005
$ 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
# 6  
Old 03-04-2005
pls try this...
for i in `cat file1`
do
b=`grep $i file2`
if [ $? -eq 0 ]
then
echo $b >> tt
fi
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with paste command

Hi, I am facing issue with paste command. It is adding spaces or tab in between. I have say 3 files with below data File_1 TH THI THIS I File_2 IS IS S IS RE S File_3 RECORD 1 CORD 2 IS RECORD 3 (3 Replies)
Discussion started by: Simanto
3 Replies

2. Shell Programming and Scripting

Need help with paste command using variables

How can I accomplish this? I basically want to merge two variables onto the same line. I can do it with two FILES this way: $ cat /tmp/users_in.list | awk -F "," '{print $2}' | cut -c -1 > first.initial $ awk -F "," '{print $1}' /tmp/users_in.list | awk '{print $1}' > last.name $ paste... (5 Replies)
Discussion started by: greenlightening
5 Replies

3. UNIX for Advanced & Expert Users

Paste command formatting

Hi, I was trying to concatenate some files using paste command along with some formatting but getting stuck. The problem is: cat 1.txt A cat 2.txt B C cat3.txt D E cat 4.txt G H (5 Replies)
Discussion started by: abhi1988sri
5 Replies

4. UNIX for Dummies Questions & Answers

paste command without spacing?

I'm trying to combine text files without a space. So if i use the paste command paste file1 file2 file3 > file4 the new file created has spacing between the contents of the once individual files. Is there some trick I can do with a delimiter that removes the spaces.. like paste -d'' or... (1 Reply)
Discussion started by: steveinthebox
1 Replies

5. Shell Programming and Scripting

Paste command - question

Hi, Below file content is output from pasting two files. Now, i want to output another file which just contains the difference on any line For example: JAY,2,,3,5,B+,JAY,2,,3,5,B+ ANN,5,,5,1,C,ANN,5,,5,2,C Line JAY seems to have no difference. However, line ANN has difference in on... (3 Replies)
Discussion started by: jakSun8
3 Replies

6. Shell Programming and Scripting

need help with cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (3 Replies)
Discussion started by: drew211
3 Replies

7. UNIX for Dummies Questions & Answers

Need help with using cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (1 Reply)
Discussion started by: drew211
1 Replies

8. UNIX for Dummies Questions & Answers

paste command

input1 15 150 input2 x 10 100 input3 y 20 200 z 34 44 cmd paste -d "\t" input1 input2 input3 >>output output (1 Reply)
Discussion started by: repinementer
1 Replies

9. Shell Programming and Scripting

command paste with variables

Hi. I have an interesting problem and i couldn't find out the solution. I have two variables in which there are a lot of lines finished by \n. I would like to concatenate this two variables into one in this format: var1var2 var1var2 . . . I could do this simply by command paste but it works... (32 Replies)
Discussion started by: samos
32 Replies

10. Shell Programming and Scripting

Paste command issue

Problem with Paste command :) Hi All, i need small suggestion in my below script... i have output in .txt format like below file1.txt 01111111 02222222 03333333 file2.txt 230125 000012 000002 now i want to merge both the file in xls or csv formate now i am using the below... (2 Replies)
Discussion started by: Shahul
2 Replies
Login or Register to Ask a Question