The sed command is attempting to substitute the string "c3h6ooh1-2" with "LONG0001 " , but it doesn't find that string, because you've put the string c3h6ooh1-2 inside quotes.
Try
sed -i 's/c3h6ooh1-2/LONG0001 /g' therm.txt
---------- Post updated at 06:49 AM ---------- Previous update was at 06:38 AM ----------
Edit: Consider adding a second whitespace at the end of the replacement string LONG.., e.g.
sed -i 's/c3h6ooh1-2/LONG0001 /g' therm.txt
^
so a 10 character string gets replaced by a 10 character string, otherwise the indentation will change.
What junior-helper suggested should make your sed command work. But, this thread is titled: "Echo printing a line in 2 lines; ecpected to print in one line". I don't see any echo commands and I don't see any indication that extraneous <newline>s are being added by anything you've shown us.
similar to previous sed commands I wanted to sed "al" and " al2h6" with some other word like LONG0003 say ...
but problem is sed will replace all "al"s
How can I get-ride of this situation?
I assume you used something like sed 's/al/LONGsomething/g' file
The "problem" is /g means global replacement, thus sed will attempt to replace all occurences of the al string, no matter where in the line.
If you remove g from the sed command like this sed 's/al/LONG/' file sed will only replace the first occurence of al .
By using a caret ^ , you explicitely tell sed to match al at the beginning of the line:
sed 's/^al/LONG/' file
The above would *almost* do what you want... Why almost? It will replace all al 's which are at the beginning of the line, so al gets LONG , and al2h6 gets LONG2h6 You get the idea.
THIS is what you want for al (it acts like replace al only found as single string, not as part of some other string too)
ljunior-helper has already pointed out some of the issues with your last post. Let me expand on that a little bit.
No. A sed substitute command will replace the text you tell it to match with the text you tell it to substitute. It will only replace all instances of al if you tell it to replace all instances of al .
If you don't want it to replace all instances of al , describe more precisely what you want to match and what text you want to use to replace the matched text.
Your latest sample input file contains four instances of al and one instance of al2h6 . One of those instances of al is at the start of a line and is followed by six spaces. One instance of al2h6 is at the start of a line and is followed by 3 spaces.
Can you precisely define what you want to match and what text you want to replace the text you match?
From your last request, I would guess that you don't want to replace al or al2h6 , but instead want to replace eight characters at the start of a line starting with al with the eight replacement characters LONG0003 . If that is what you want, that would be something more like:
sed 's/^al....../LONG0003/' file
Please stop making us guess at what you want and give precise details about what you are trying to do.