I have a file that looks like this...
a
b
c
d
e
f
g
h
i
I would like to it to be like this
a b c
d e f
g h i
Thanks
I have a file that looks like this...
a
b
c
d
e
f
g
h
i
I would like to it to be like this
a b c
d e f
g h i
Thanks
Split the file
split -3 file79 f79s
creating three files f79saa, f79sab, f79sac
Change new-lines to blanks for each file, like
tr "\n" " " <f79saa > f79a
and then the other two
Finally, create finished file by cat'ing the three files
cat f79a > file79new
cat f79b >> file79new
cat f79c >> file79new
I thought I figured a quicker way, but the following (while doing something kind of cool) did not provide what you were looking for. However, I thought it would be a good entry to exist in the forum's repositor of Q&A.
> cat file79
a
b
c
d
e
f
g
h
i
> split -3 file79 f79s | paste f79saa f79sab f79sac
a d g
b e h
c f i
Another one:
awk '{printf("%s%s",$0,NR%3?" ":"\n")}' file
Regards
Hi.
Similarly:
#!/bin/bash -
# @(#) s1 Demonstrate paste, column to row.
echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) paste
set -o nounset
echo
FILE=${1-data1}
echo " Data file $FILE:"
cat $FILE
echo
echo " Results, paste default:"
paste - - - < $FILE
echo
echo " Results, paste separator:"
paste -d" " - - - < $FILE
exit 0
Producing:
% ./s1
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
paste (coreutils) 5.2.1
Data file data1:
a
b
c
d
e
f
g
h
i
Results, paste default:
a b c
d e f
g h i
Results, paste separator:
a b c
d e f
g h i
cheers, drl
This only work if the file only contained 1 word and no spaces. My actual file has spaces for example....
a 123
b 123
c 123
and I would like
a 123 b 123 c 123
I'm not sure I follow what I should be doing .
nawk 'ORS=(FNR%3)?FS:RS' myFile
as an alternative to a more classic 'paste'
That Works, but I Just need to make sure my file is consistent if not I will just have huge problem.