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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assistance with merge script 1

Status
Not open for further replies.

jping45

Technical User
Aug 22, 2001
49
US
I have about 70 files to merge into one, each file has about 7 lines or so of data. The final format has to be:

DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3
DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3
DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3
DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3
DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3
DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3
DATA FROM FILE1 DATA FROM FILE2 DATA FROM FILE3

DATA FROM FILE4 DATA FROM FILE5 DATA FROM FILE6
DATA FROM FILE4 DATA FROM FILE5 DATA FROM FILE6
DATA FROM FILE4 DATA FROM FILE5 DATA FROM FILE6
DATA FROM FILE4 DATA FROM FILE5 DATA FROM FILE6
... So on and so forth until all 70 plus files have been processed. I am able to merge three files togther on the command line using the pr command (and various flags). My question is how to get all the files togehter in the format mentioned above? Any hints would be greatly appreciated.

 
See the [tt]paste[/tt] command ("[tt]man paste[/tt]").
 
assuming all the files are in one directory and nothing else is in that dir, something like this?:

outfile=/path/to/file
cd /path/to/dir
for file in $(ls)
do
# use pr to print three files side by side
pr <yourflags> $1 $2 $3
# or "paste" them together
#paste -d' ' $1 $2 $3
# empty line as per your example above
echo
# skip to next three files
shift 3
done >${outfile}


HTH,

p5wizard
 
p5wizard,
thanks for the response, however I'm not sure I understand the loop. It looks like you are setting the $file variable to the output from the ls command. where are $1-$3 being set?
 
Well that's what I get when answering blindly :-(... It doesn't even work that way I'm afraid.

this should work:
cd /path/to/dir
set -- $(ls)
while [ $# -gt 0 ]
do
# now use $1 $2 and $3
paste...
# skip to next 3 files and subtract 3 from $#
shift 3
# empty line
echo
done >/path/to/outfile



HTH,

p5wizard
 
p5wizard...
outstanding! Thanks for the assistance and quick replies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top