Convert rows into space-delimited line and vice versa

While dealing with text processing jobs we would like to convert a selection of rows separated by \n and convert it to space delimited single line. 

We will do this with 'tr' - unix tool that translates, deletes, squeezes characters from standard input and writes the same to standard output. "Awk" is a powerful tool used to perform pattern scannind and processing language and it is one of the important commands, a powerful linux user should be aware of its usage.

 
To convert rows into a space-delimited line and save to a file:
$ cat intput.txt
ankit
shah
is
my
name
I
am
awesome
$ cat input.txt | tr "\n" " " | tee output.log
ankit shah is my name I am awesome

To convert spaces to line break (newline) and save to a file:
$ cat intput.txt
Hi how are you doing
sed -e 's/\s\+/\n/g' input.txt | tee output.txt
Hi
how
are
you
doing

Comments

Popular posts from this blog

SOX - Sound eXchange - How to use SOX for audio processing tasks in research.

Sox of Silence - Original post - http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/

How to get video or audio duration of a file using ffmpeg?