Computing.Net > Forums > Unix > scripts to merge file vertically

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

scripts to merge file vertically

Reply to Message Icon

Name: tenghin
Date: October 14, 2003 at 22:03:02 Pacific
OS: hpux
CPU/Ram: PA-RISC
Comment:

Hi,
anyone has any idea how to merge two files vertically, meaning first line of file1 merge with first line of file2, second line of file1 with second line of file2...

regards,
y



Sponsored Link
Ads by Google

Response Number 1
Name: Frank
Date: October 15, 2003 at 05:14:48 Pacific
Reply:

One quick and dirty way would be:

#!/bin/ksh
typeset -i RecordA=0
typeset -i RecordB=0
typeset -i RecordCountA=0
typeset -i RecordCountB=0
typeset -i Rest=0

InfileA=/u/a1xrdb1/i
InfileB=/u/a1xrdb1/x

RecordA=`wc -l ${InfileA} | awk '{print $1}'`
RecordB=`wc -l ${InfileB} | awk '{print $1}'`

while [ ${RecordA} -gt ${RecordCountA} -a ${RecordB} -gt ${RecordCountB} ]
do
RecordCountA=RecordCountA+1
RecordCountB=RecordCountB+1
RowA=`head -${RecordCountA} ${InfileA}|tail -1`
RowB=`head -${RecordCountB} ${InfileB}|tail -1`
echo ${RowA} ${RowB}
done
if [ ${RecordCountA} -lt ${RecordA} ]
then
Rest=RecordA-RecordCountA
tail -${Rest} ${InfileA}
fi

if [ ${RecordCountB} -lt ${RecordB} ]
then
Rest=RecordB-RecordCountB
tail -${Rest} ${InfileB}
fi


no Risk no fun
Frank


0

Response Number 2
Name: covina
Date: October 20, 2003 at 12:51:06 Pacific
Reply:

paste file1 file2 > file12


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Regular expressions Expr Quoting



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: scripts to merge file vertically

script to move file www.computing.net/answers/unix/script-to-move-file/4235.html

Script to scan files for a string www.computing.net/answers/unix/script-to-scan-files-for-a-string/7532.html

Script to process/search a csv file www.computing.net/answers/unix/script-to-processsearch-a-csv-file/5115.html