Jumat, Desember 03, 2010

How to replace newline "\n" on Unix shell

I want to replace all new line characters on a file using Unix shell. Just found it is quite difficult to do it using sed command because sed operates line by line and never sees the newline endings. Yeah, instead of sed command, tr command is a solution for this.

Let say I want to replace '\n' character on file named sample.log with ' ' (space) character. Instead of using

sed -i 's/\n/ /g'

command which is failed, I use

cat sample.log | tr '\n' ' ' > sample.output

command. The result will be stored in sample.output file.

Tidak ada komentar:

Posting Komentar