Unix/Linux Go Back    


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

Paste many files together side by side

UNIX for Dummies Questions & Answers


Tags
join, multiple files, paste

 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-13-2012   -   Original Discussion by shaz1990
shaz1990's Unix or Linux Image
shaz1990 shaz1990 is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 14 April 2012, 9:17 AM EDT
Posts: 2
Thanks: 3
Thanked 0 Times in 0 Posts
Error Paste many files together side by side

Hi,
Thank you for your help in advance Linux.

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 Linux
Sponsored Links
    #2  
Old Unix and Linux 04-13-2012   -   Original Discussion by shaz1990
analyst's Unix or Linux Image
analyst analyst is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 20 September 2012, 12:07 PM EDT
Posts: 20
Thanks: 3
Thanked 1 Time in 1 Post
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)
Sponsored Links
    #3  
Old Unix and Linux 04-13-2012   -   Original Discussion by shaz1990
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 26 May 2018, 5:40 PM EDT
Location: NM
Posts: 11,393
Thanks: 616
Thanked 1,158 Times in 1,067 Posts
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 Unix and Linux 04-14-2012   -   Original Discussion by shaz1990
shaz1990's Unix or Linux Image
shaz1990 shaz1990 is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 14 April 2012, 9:17 AM EDT
Posts: 2
Thanks: 3
Thanked 0 Times in 0 Posts
People you are a lifesaver!!!

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combining two single column files side-by-side sajal.bhatia Shell Programming and Scripting 1 08-07-2011 04:53 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



All times are GMT -4. The time now is 09:06 PM.