DONG DAO
DONG DAO

Reputation: 19

C-shell: print result from row to column

I have outputs:

1 rpt 4 qor 5 are 6 oip

I want it to become :

1 rpt
4 qor
5 are
6 oip

This is my code:

set d = `sort "04.txt" | uniq -c`
echo $d

Upvotes: 1

Views: 315

Answers (2)

Akshay Hegde
Akshay Hegde

Reputation: 16997

akshay@sys:~$ cat file 
1 rpt 4 qor 5 are 6 oip

akshay@sys:~$ sed 's/ /\n/2; P; D'  file 
1 rpt
4 qor
5 are
6 oip

akshay@sys:~$ awk -v n=2 '{for (i=n+1; i<=NF; i+=n) $i = "\n" $i}1'  file
1 rpt 
4 qor 
5 are 
6 oip

akshay@sys:~$ awk -v RS=" " '{$1=$1; ORS=NR%2?FS:"\n" }1'  file 
1 rpt
4 qor
5 are
6 oip

Upvotes: 2

RavinderSingh13
RavinderSingh13

Reputation: 133680

With your shown samples, please try following.

xargs -n 2 < Input_file

From man xargs:

-n max-args, --max-args=max-args Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case xargs will exit.

Upvotes: 3

Related Questions