Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join lines from two files - Unix ksh 1

Status
Not open for further replies.

nsivas

Programmer
Nov 29, 2000
9
US
I want to join the each line of two files in order. ie.,1st line of the file1 will be joined to the first line of the file2 and vice versa, the ouput has to be moved to another file.

Please help me in this.

Thanks
Siva
 
#!/bin/sh

cat /tmp/a | sed -n '1p' >> d
cat /tmp/b | sed -n '1p' >> d

where a, b and d are files

Hope this helps
Tony
 
Thanks boebox, the answer works very well. Now how do I convert this script for the all the lines in the file? Can you please help on this

Regards
Siva
 
Thanks Tony, the task completed.

total=23
m=1
n=1
while (( $total >= $m ))
do
cat $HOME/file1 | sed -n "$m"p >> file3
cat $HOME/file2 | sed -n "$n"p >> file3
(( m = $m + 1 ))
(( n = $n + 3 ))
done

Siva
 
Siva

Sorry I did not respond, work is realy busy, but I did start to write the script(good intentions), but I see you are using the same logic I had in mind.

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top