I have a variable, $TESTVAR that has a '\n' character in it
how can I remove all space characters and new line characters on either side of this variable value.
Do you man by what method can you remove them? As in editing the file with
vi and deleting the characters with an x and then saving with wq. Can you be more specific please?
You can do this with sed, but you may have to know how many newline chars there are. For example:
$ T1="this \nis a \ntest"
$ echo $T1 | sed '{
N
N
s/\n//g
s/ //g
}'
produces: thisisatest
The sed script says: cancatenate the next two lines (the N's), then replace newlines with nothing, then replace spaces with nothing.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.