Append Line From a File To Another File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append Line From a File To Another File
# 1  
Old 05-29-2007
PHP Append Line From a File To Another File

Dear all,

i have a problem...
i have 2 files
first one is
A.txt

5268345674 ABCDEF1 ABC 10121 EXT
5265087087 ABCDEF3 ABC 10221 EXT
5268979998 ABCDEF4 ABC 10321 EXT

second one is
B.txt

10121 52658450 R1MEXI2 0
10221 52653889 R1SLRC2 0
10321 52657319 R1SAFE1 0

now i want the output like

5268345674 ABCDEF1 ABC 10121 EXT 52658450 R1MEXI2 0
5265087087 ABCDEF3 ABC 10221 EXT 52653889 R1SLRC2 0
5268979998 ABCDEF4 ABC 10321 EXT 52657319 R1SAFE1 0

in the output file only the first field from B.txt i want to remove...

Like the above output using awk or shell or sed etc

Thanks in advance
Regards,
Pankaj
# 2  
Old 05-29-2007
Code:
join -1 4 -2 1 -o1.1,1.2,1.3,1.4,1.5,2.2,2.3,2.4 A.txt B.txt

# 3  
Old 05-29-2007
Append Line From a File To Another File

Dear lorcan

Thanks for your quick reply but can you please explain me your code?

Thanks,
Regards,
Pankaj
# 4  
Old 05-29-2007
Quote:
Originally Posted by panknil
Dear lorcan

Thanks for your quick reply but can you please explain me your code?

Thanks,
Regards,
Pankaj
join -1 4 -2 1 -o1.1,1.2,1.3,1.4,1.5,2.2,2.3,2.4 A.txt B.txt

where -1 option specifies the first file and the argument 4 represents your column to be matched with the second file.

-2 option specifies the second file and argument 1 represents your column to be matched

and -0 option is just to print the fields from the respective file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Append Text File from another File in line 6

Hi, Anyone can help on how to append a file1.txt into file2.txt after line 3 using sed command. file1.txt 1. testa 2. testb 3. testc 4. testd 5. test5 6. test6 file2.txt break here this is a test break end here output 1. testa 2. testb (1 Reply)
Discussion started by: fspalero
1 Replies

3. Shell Programming and Scripting

conditional append one line in file.

Hi, Unix gurus, I have a requirement as following: checking existing file, if the file only contain one line. then append "No data" else keep existing file as is. can i achieve this by in command line without write a script. :wall: Thanks in advance. (4 Replies)
Discussion started by: ken002
4 Replies

4. Shell Programming and Scripting

Append to exisiting file on same line.

File Format ABC|ABC|ABC| need to add another text after last | which would a unix command output. ---------- Post updated at 02:05 PM ---------- Previous update was at 01:45 PM ---------- wc -l file| awk '{print $1}' | sed 's/$//' >> existingfile It still adds to new line (4 Replies)
Discussion started by: dinjo_jo
4 Replies

5. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

6. Shell Programming and Scripting

Append each line to next previous line in a file

Hi all, Please help me in providing sample code to append the following 4 lines in one row. Input : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 1 EXTERNAL ALARM DOOR ALARM Output should be : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 ... (8 Replies)
Discussion started by: sudhakaryadav
8 Replies

7. Shell Programming and Scripting

Append to end of each line of file without a temp file.

Hello I am trying to append an incrimenting number to the end of each line I have it working with a temp file. But I want to do this without a temp file. a=1 cat "file" | while read LINE do echo "$LINE, $a" >> filewithnumbers a=`expr $a + 1` ... (4 Replies)
Discussion started by: rorey_breaker
4 Replies

8. UNIX for Dummies Questions & Answers

How to Append a Value to each line of the file

Hi, We have Multiple source files which has some data, I need a K shell script which will append number '1' as the last character to all the lines of the first file and then increments the value and appends '2' to all the lines to the next file and so on. For Example Incoming file 1 ... (11 Replies)
Discussion started by: dsshishya
11 Replies

9. Shell Programming and Scripting

Append a field to the end of each line of a file based on searching another file.

Hi All, I have two comma separated value(CSV) files, say FileA and FileB. The contents looks like that shown below. FileA EmpNo,Name,Age,Sex, 1000,ABC,23,M, 1001,DES,24,F, ... (2 Replies)
Discussion started by: ultimate
2 Replies

10. UNIX for Dummies Questions & Answers

Large file need to append to each line

I have a few large files that need to have a ,A appended to the end of each record. I though about using sed but never used it before and the man is not intuitive nor have I found examples. This is what I tried for file name bob sed '\a,A' bob from what I get if you do not supply a range... (1 Reply)
Discussion started by: r1500
1 Replies
Login or Register to Ask a Question