0

Hello i have this file.txt

a=a

b=b

c=c

d=d

e=e

f=f

. etc (about 150 rows)

I need the output to be:

a b c d e f ....

a b c d e f ....

I already tried using paste -d " " - - < file.txt but i need something to work with huge number of rows to columns.

Thank you in advance.

Johnny
  • 53
  • 1
  • 9
  • Possible duplicate of [Transpose a file in bash](http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash) with a slight modification in the input-field-separator – Inian Oct 05 '16 at 15:13

3 Answers3

1

You can separate the file using the internal field separator:

while IFS== read -r left right; do echo $left; done < "test.txt" | xargs

This gives you the left side. For the right side, you could do

while IFS== read -r left right; do echo $right; done < "test.txt" | xargs

If you are talking about only 150 rows, scanning the file twice should be finde.

mrks
  • 8,033
  • 1
  • 33
  • 62
1

Try this :

awk -F= '{
    arr1[NR]=$1
    arr2[NR]=$2
}
END{
    for (i in arr1) {
        printf("%s ", arr1[i])
    }
    print""
    for (i in arr2) {
        printf("%s ", arr2[i])
    }
    print ""
}' file

Output:

a b c d e f 
a b c d e f
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
1

mash of echo, cut and tr

$ cat ip.txt 
a=1
b=2
c=3
d=4

$ echo $(cut -d= -f1 ip.txt | tr '\n' ' ') ; echo $(cut -d= -f2 ip.txt | tr '\n' ' ')
a b c d
1 2 3 4
Sundeep
  • 23,246
  • 2
  • 28
  • 103