Hello,
I have output in the matrice form , for example:
1 2 3 4
a b c d
jim joe sue tom
how can I convert this line-column data into a row as follows
1 2 3 4 a b c d jim joe sue tom
thank you
Hello,
I have output in the matrice form , for example:
1 2 3 4
a b c d
jim joe sue tom
how can I convert this line-column data into a row as follows
1 2 3 4 a b c d jim joe sue tom
thank you
tr '\n' ' ' < infile
awk '$1=$1' RS= infile
Try this,
paste -s inputfile
xargs < infile
thank you all, I am trying the codes
$ ruby -00 -ne 'puts $_.split.join(" ")' file
1 2 3 4 a b c d jim joe sue tom
Pravin, Scrutinizer and Kurumi thank you very much... Is it possible to convert it to a column data like:
1
2
3
4
a
b
.
.
.
best regards
$ ruby -ane '$F.each{|x| puts x}' file
xargs -n1 < infile
awk '$1=$1' OFS="\n" infile
tr '[ \t]' '[\n*]' < infile
great codes... all of them works well... thank you...
---------- Post updated at 03:10 PM ---------- Previous update was at 02:59 PM ----------
awk '$1=$1' OFS="\n" infile
I have hundreds of lines and columns. It is seen that the fastest command is above.
thank you all
tr ' ' '\n' < inputfile
suppose that we have column data
1
2
3
4
5
6
.
.
.
how can I generate a new column data by summing the elements of 3 by 3 that gives a result as follows
6
15
.
.
.
THANK YOU
something like this:
awk 'NR%3==0 { sum = sum + $0 ; print sum ; sum = 0 ; next } { sum = sum + $0 }' file_name
Assuming that the number of lines in file is a multiple of 3:
sed 'N;N;y/\n/+/' file | bc
paste -d+ - - - < file | bc
For a more general case (the final number will be the sum of 1 or 2 lines if that's all that remains):
paste -d+ - - - < file | sed '$s/++*$//' | bc
Dear Panyam and alister, both the codes work perfect.
thank you for your time