I have the following input:
Value1|Value2|Value3|Value4@@ Value5|Value6|Value7|Value8@@ Value9|etc...
In my bash script I would like to replace the @@
with a newline. I have tried various things with sed but I'm not having any luck:
line=$(echo ${x} | sed -e $'s/@@ /\\\n/g')
Ultimately I need to parse this whole input into rows and values. Maybe I am going about it wrong. I was planning to replace the @@
with newlines and then loop through the input with setting IFS='|'
to split up the values. If there is a better way please tell me, I am still a beginner with shell scripting.
Using pure BASH string manipulation:
How about:
This will work
replaces
@@
with new lineFinally got it working with:
Adding the single quotes around \\n seemed to help for whatever reason
I recommend using the tr function
For example:
If you don't mind to use perl: