Replace vertical lines in Bash

I find it difficult to complete my script, as there is this part that does not work the way I wanted.

I have this line in my script:

cat /home/tmp/temp1.txt | awk '{gsub("~",RS);gsub("*",RS);print}' >  /home/tmp/temp.txt

It works great, yes. But when I do something like this:

cat /home/tmp/temp1.txt | awk '{gsub("|",RS);print}' >  /home/tmp/temp.txt

It doesn't work at all. I wanted to change all my vertical stripes to a new line, and yet I cannot achieve this. Please help me with this. Thanks

+4
source share
2 answers

You can do all replacements in one awk as follows:

awk '{gsub(/[*~|]/, RS)} 1' /home/tmp/temp1.txt

, . [...] , .

/.../ gsub .

+4

, tr, :

echo "hi|there|my|friend"   |    tr '|' '\n'
hi
there
my
friend

, :

tr '|' '\n'  < /home/tmp/temp.txt
+1

Source: https://habr.com/ru/post/1605687/


All Articles