Deleting newline and making output in single line with spaces

HI

I have a file line
vi Input

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

When i do
awk -vORS="" '1' inputFile
i get 446447448449450451452453454455456457458459460

but i need output as

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460

Please help

Using tr:

[user@host ~]$ cat file | tr '\n' ' '
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 [user@host ~]$

Old school:

[user@host ~]$ while read line; do printf "%s " $line; done < file
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 [user@host ~]$
1 Like

It worked

cat file | tr '\n' ' '

:slight_smile:

You just had to use the proper ORS

bash-3.2$ cat inputFile 
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
bash-3.2$ awk -v ORS=" " '1' inputFile
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 bash-3.2$

@MR.Bean
It can be written shorter :slight_smile:

awk 1 ORS=" " file

Hello Jotne,

could you please explain how a new line or tab will work in

 ORS 

, I have tried and it is giving the error as follows.

test file is:

$ cat small_data
09016ad2801ff702 09016ad2801ff703 09016ad280201300 09016ad280201302

Command used is:

$ awk 1 ORS="\\n" small_data

Output is as follows:

09016ad2801ff702 09016ad2801ff703 09016ad280201300 09016ad280201302

Thanks,
R. Singh

What output did you expect?

echo "09016ad2801ff702 09016ad2801ff703 09016ad280201300 09016ad280201302" | awk 1 RS=" "
09016ad2801ff702
09016ad2801ff703
09016ad280201300
09016ad280201302

ORS = output record selector
RS = record selector (input)

Read this: 8 Powerful Awk Built-in Variables � FS, OFS, RS, ORS, NR, NF, FILENAME, FNR (link removed)

If you would like to eliminate the trailing space and have the resulting line be a valid text file:

paste -sd ' ' file

Regards,
Alister