Paste command formatting

Hi,

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

The problem is:

cat 1.txt
A
cat 2.txt
B
C
cat3.txt
D
E
cat 4.txt
G
H
I
paste -d "%" 2.txt 3.txt > 5.txt
B%D
C%E
paste -d "%" 1.txt 5.txt 4.txt
A%B%D%G
%C%E%H
%%I

but

Expected Output

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

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...)

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.

But what would be the criterion? The percentage signs introduced by the past command are related to the number of input files, for example

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

So just leave out the intermediate file

1 Like

but thats just the scenario i.e. file names 1,2,3,4...
files names are different , how to handle the formatting with this?

Hi,

Just give your all file names in one instance,

paste -d"%" file1 file2 file3 file4

Cheers,
Ranga:)