tr command¶
The tr command is very useful command in deleteing or replaceing character
Replace Newline with Comma¶
Let starts a new session and assigns it a name:
Run cat test.txt | tr -s '\n' ',', the -s flag determina what you wan to replace, here we interestted in new line \n
drop repeated spaces¶
We use tr -s ' ' to convert any repeated spaces into a single space:
$ cat test2.txt
c1 c2 c3 c4
1 2 3 4
1 2 3 4
1 2 3 4
$ cat test.txt | tr -s ' '
c1 c2 c3 c4
1 2 3 4
1 2 3 4
1 2 3 4
samamiri@beluga1:~$
specified characters¶
Let drop the digitals from file
Or invertly keep the digital
To convert characters from lower case to upper case, you can either specify a range of characters or use the predefined character classes.