Paste command formatting | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Paste command formatting

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-26-2012
abhi1988sri abhi1988sri is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 October 2013, 2:42 AM EDT
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Paste command formatting

Hi,

I was trying to concatenate some files using paste command along with some formatting but getting stuck.

The problem is:


Code:
cat 1.txt
A


Code:
cat 2.txt
B
C


Code:
cat3.txt
D
E


Code:
cat 4.txt
G
H
I


Code:
paste -d "%" 2.txt 3.txt > 5.txt
B%D
C%E


Code:
paste -d "%" 1.txt 5.txt 4.txt
A%B%D%G
%C%E%H
%%I

but

Expected Output

Code:
A%B%D%G
%C%E%H
%%%I

problem is the number of lines present in the file. with absence of number of fields, the percentage sign during concatenation should vary accordingly. This is just a scenario.

Please help.

Regards

Abhinav

Last edited by Scrutinizer; 12-26-2012 at 05:21 AM.. Reason: code tags
Sponsored Links
    #2  
Old 12-26-2012
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 April 2014, 8:57 AM EDT
Location: Amsterdam
Posts: 8,899
Thanks: 230
Thanked 2,147 Times in 1,928 Posts
There should be only to 2 percent signs on the 3rd row, the extra % sign on the two rows above are part of the input file (they stem from a previous paste operation...)
Sponsored Links
    #3  
Old 12-26-2012
abhi1988sri abhi1988sri is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 October 2013, 2:42 AM EDT
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Yes, what you are saying is correct.
The output of command will provide the output in that way only.

But we need the output to be in the form as shown in expected output.
Is there a way to format the output given by paste command to give the output as expected output.
May be using awk.. but dont know how.
    #4  
Old 12-26-2012
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 April 2014, 8:57 AM EDT
Location: Amsterdam
Posts: 8,899
Thanks: 230
Thanked 2,147 Times in 1,928 Posts
But what would be the criterion? The percentage signs introduced by the past command are related to the number of input files, for example


Code:
paste -d% [1234].txt
A%B%D%G
%C%E%H
%%%I

So just leave out the intermediate file

Last edited by Scrutinizer; 12-26-2012 at 05:51 AM..
The Following User Says Thank You to Scrutinizer For This Useful Post:
abhi1988sri (01-01-2013)
Sponsored Links
    #5  
Old 12-26-2012
abhi1988sri abhi1988sri is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 October 2013, 2:42 AM EDT
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
but thats just the scenario i.e. file names 1,2,3,4...
files names are different , how to handle the formatting with this?
Sponsored Links
    #6  
Old 12-26-2012
rangarasan's Avatar
rangarasan rangarasan is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 11 April 2014, 8:41 AM EDT
Location: Chennai, India
Posts: 494
Thanks: 9
Thanked 124 Times in 120 Posts
paste

Hi,

Just give your all file names in one instance,


Code:
paste -d"%" file1 file2 file3 file4

Cheers,
Ranga
Sponsored Links
Closed 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
Paste command - question jakSun8 Shell Programming and Scripting 3 02-13-2012 10:31 PM
Can't paste in command line. louboulos Shell Programming and Scripting 8 12-19-2011 10:25 AM
paste command repinementer UNIX for Dummies Questions & Answers 1 09-23-2009 07:35 AM
How to feed the output from grep command to paste command ks_reddy Shell Programming and Scripting 2 04-04-2009 03:47 AM
paste command mariner UNIX for Advanced & Expert Users 5 03-04-2005 01:42 AM



All times are GMT -4. The time now is 09:35 AM.