Results 1 to 3 of 3
I have a series of text files of same height.
File A
--------
1
1
1
1
1
File B
--------
2
2
2
2
2
...
...
Is there ...
- 04-06-2010 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 8
Append to the right side ?
I have a series of text files of same height.
File A
--------
1
1
1
1
1
File B
--------
2
2
2
2
2
...
...
Is there easy way to append sideways ?
CombinedFile
123...
123...
123...
123...
123...
Thanks !
- 04-06-2010 #2
You could try bash's process substitution.
Or you could try something like below:
Which reads from three files(one, two, three) one line at a time.Code:#! /bin/sh while read f do echo -n $f if read g then echo -n $g fi < two if read h then echo -n $h fi < three echo done < one
My bad that won't work but this will:
Code:#! /bin/sh exec 3<one exec 4<two exec 5<three while read f do echo -n $f if read g then echo -n $g fi <&4 if read h then echo -n $h fi <&5 echo done <&3 exec 3<&- exec 4<&- exec 5<&- exit 0
Last edited by gerard4143; 04-07-2010 at 11:50 AM.
Make mine Arch Linux
- 04-07-2010 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
The paste command is designed for this:
producing:Code:#!/usr/bin/env bash # @(#) s1 Demonstrate paste, default parallel. # Test run as external user. # export PATH="/usr/local/bin:/usr/bin:/bin" # Infrastructure details, environment, commands for forum posts. set +o nounset LC_ALL=C ; LANG=C ; export LC_ALL LANG echo ; echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG" echo "(Versions displayed with local utility \"version\")" c=$( ps | grep $$ | awk '{print $NF}' ) version >/dev/null 2>&1 && s=$(_eat $0 $1) || s="" [ "$c" = "$s" ] && p="$s" || p="$c" version >/dev/null 2>&1 && version "=o" $p paste set -o nounset # Sample files, with head & tail as a last resort. specimen data* \ || { head -n 5 data* ; echo " --" ; tail -n 5 data* ; } echo echo " Results:" paste -d "" data* exit 0
See man paste for details ... cheers, drlCode:% ./s1 Environment: LC_ALL = C, LANG = C (Versions displayed with local utility "version") OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64 Distribution : Debian GNU/Linux 5.0 GNU bash 3.2.39 paste (GNU coreutils) 6.10 Whole: 5:0:5 of 4 lines in file "data1" 1 1 1 1 Whole: 5:0:5 of 4 lines in file "data2" 2 2 2 2 Whole: 5:0:5 of 4 lines in file "data3" 3 3 3 3 Results: 123 123 123 123
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote