Home Man
Search
Today's Posts
Register

This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in the UNIX for Beginners Questions & Answers forum.

Paste many files together side by side

Tags
beginners, join, multiple files, paste

 

 
Thread Tools Search this Thread
# 1  
Old 04-13-2012
Error Paste many files together side by side

Hi,
Thank you for your help in advance .

I have thousands of files like...

file01
file02
file03
.
.
.
file6324

I would like to paste every other file side by side so it looks like

file01 file02
file03 file04
...e.t.c
file6323 file6324

In addition odd files has the following type of layout:

Preamble(Containing random stuff) (11 lines)

Data Table (11 columns all together) i.e
1 number
2 number
3 number
4 number
...e.tc

In addition even files has the following type of layout:

Preamble(Containing random stuff) (4 lines)

Data Table (columns all together 3) i.e
1 number
2 number
3 number
4 number
...e.tc

essentially joining tables together without the preamble jargon.

Once again thankyou in advance. Cheers
# 2  
Old 04-13-2012
I am myself a beginner, but a shell script will help

while

do

start a counter c = 1:
d = c+1
then Something like
if elif to see even odd files, use sed 11d to clear the preamble or sed 4d depending on condition

then 'paste file${c} file${d}

increment c: c=$((c+1))

done


Good luck
The Following User Says Thank You to analyst For This Useful Post:
shaz1990 (04-14-2012)
# 3  
Old 04-13-2012
Use the paste command

Code:
#!/bin/bash

cnt=1
while [ $cnt -le 6324 ]
do
# use files in numeric order
# create odd filename
     fname1=$(printf "file%02d" $cnt)
     cnt=$(( $cnt + 1 ))
#create even filename
     fname2=$(printf "file%02d" $cnt)
     cnt=$(( $cnt + 1))
# remove preamble 11 lines  odd file
     awk ' NR>11 ' $fname1 > /tmp/1
# remove preamble 4 lines  even file
     awk ' NR>4 ' $fname2 > /tmp/2
# put file contents into file with name like "file01file02" ... "file6323file6324"
     paste /tmp/1 /tmp/2 > ${fname1}${fname2}
done

This does not overwrite the old files, it makes new ones.
The Following User Says Thank You to jim mcnamara For This Useful Post:
shaz1990 (04-14-2012)
# 4  
Old 04-14-2012
People you are a lifesaver!!!

Cant thank you guys enough!!! been trying to solve this for the last few weeks and now it works. Much appreciated, seriously thanks.
 

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Import 2 columns from 8 .csv files into pandas df (side by side) and write a new csv Zam_1234 Shell Programming and Scripting 3 05-20-2015 06:30 PM
Merging two text files side by side FishTornado Shell Programming and Scripting 4 12-18-2012 03:56 PM
Combining two single column files side-by-side sajal.bhatia Shell Programming and Scripting 1 08-07-2011 04:53 AM
AWK to merge multiple files side by side kanthrajgowda Shell Programming and Scripting 5 06-01-2011 10:20 AM
printing 3 files side by side based on similar values in rows zerofire123 Shell Programming and Scripting 4 12-20-2010 01:36 AM
Paste two file side by side together based on specific pattern match problem patrick87 Shell Programming and Scripting 6 12-18-2009 06:15 AM
How to Merge / combine / join / paste 2 text files side-by-side cajunfries Shell Programming and Scripting 3 04-27-2009 07:25 PM
Script to place selected columns from a group of files side by side in a new file ks_reddy Shell Programming and Scripting 8 02-12-2009 11:09 AM
How to Merge Two .xls files side by side into a single .xls jagadish99 Shell Programming and Scripting 2 09-24-2008 06:44 AM
How to Merge Two .xls files side by side into a single .xls jagadish99 Shell Programming and Scripting 0 08-27-2008 06:38 AM


All times are GMT -4. The time now is 04:51 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password