1

I have a text file with over 10000 lines and use this code to separate some things:

BS=`cat myfile | grep myword`  
cutbs=`cut -d'=' -f2 $BS | sort -u
$cat cutbs  
qwe  
asd  
zxc

Now I would like print output of this sort in one line like below:

$cat cutbs  
qwe asd zxc
lehr88
  • 29
  • 4
  • 2
    Maybe this can help you : http://stackoverflow.com/questions/15580144/concatenate-many-lines-of-output-to-one-line – Pierre Nov 23 '13 at 10:46

2 Answers2

2

You can simply use paste -s:

cut -d'=' -f2 $BS | sort -u | paste -s

Sun OS version:

cut -d'=' -f2 $BS | sort -u | paste -s -

See:

$ cat tubs 
qwe  
asd  
zxc
$ cat tubs | paste -s -
qwe     asd     zxc

The items are tab-separated, but you can choose the delimiter. Example with a space:

$ cat tubs 
qwe  
asd  
zxc
$ cat tubs | paste -s -d' ' -
qwe asd zxc

Beware with your example:

cutbs=`cut -d'=' -f2 $BS | sort -u`

creates a variable, then you run

$cat cutbs

which outputs the contents of a file, totally unrelated to $cutbs

damienfrancois
  • 52,978
  • 9
  • 96
  • 110
0

You could use sed:

$ cat $cutbs | sed -n -e ':start $!{N;s/\n/ /;t start;};P;D;'

Or tr:

$ cat $cutbs | tr '\n' ' '
R.Sicart
  • 671
  • 3
  • 10