Giving the string:
foo='Hello \
World! \
x
we are friends
here we are'
Supose there are also tab characters mixed with spaces after or before the \
character.
I want to replace the spaces, tabs and the slash by only a space. I tried with:
echo "$foo" | tr "[\s\t]\\\[\s\t]\n\[\s\t]" " " | tr -s " "
Returns:
Hello World! x we are friend here we are
And the result I need is:
Hello World! x
we are friends
here we are
Some idea, tip or trick to do it? Could I get the result I want in only a command?
tr
deals in lists of characters, but you appear to be trying to pass it a regular expression (\s*\\\s*\n\s*
). This may appear to work at first, but isn't actually doing what you expect; in this case, (partly because of quirks in backslash parsing in double quotes), it'll replace "\", "s", "*", and newline characters with spaces. – Menefee