Shell Newline

Solved
bibitun Posted messages 10 Status Membre -  
bibitun Posted messages 10 Status Membre -
Hello,
I have a problem that I've been trying to solve since Friday without success. In fact, I'm writing a shell script, where I need to insert a line using sed, followed by a newline and then another line:
sed s/line_to_replace/line1\nline2/g file > file;
The problem is that the newline is not recognized, and I just get line1nline2.
I doubled the double slash, and I get the same thing; when I triple it, I get line1\nline2.
I should mention that I'm using Putty to connect to the server; unfortunately, I have no choice of tool.
Thank you for your help.

6 réponses

zipe31 Posted messages 34620 Registration date   Status Contributeur Last intervention   6 500
 
Hello,

What operating system are you using on your server?
What version of "sed"?

Try with the ASCII code:

sed 's/lign_remplacer/ligne1\x0Aligne2/g' fichier > fichier

It's a ZERO and not a capital O...

--
Zen my nuggets ;-)
Do something for the environment, close your windows and adopt a penguin.
0
bibitun Posted messages 10 Status Membre
 
Always the same problem: it shows me ...line1x0Aline2...
How can I know the version of the server and the sed command please?
Thank you
0
zipe31 Posted messages 34620 Registration date   Status Contributeur Last intervention   6 500
 
Do you at least know if the server is running GNU/Linux or UNIX?

Try:

lsb_release -a or cat /etc/{release,version,issue}


For "sed":

sed --version
0
bibitun Posted messages 10 Status Membre
 
The command you gave me didn't work, I tried the oslevel command, it returned: 5.2.0.0.
uname -a returned: AIX xxxxx 2 5 .....
For sed, the command didn't work.
0
zipe31 Posted messages 34620 Registration date   Status Contributeur Last intervention   6 500
 
Indeed, on AIX, "sed" can be rather temperamental ;-((

Try it like this:

sed 's/lign_remplacer/ligne1\<ENTREE> ligne2/g' file > file


<ENTREE> should be executed, not taken literally, right? ;-))
0
bibitun Posted messages 10 Status Membre
 
Could you please explain this entry story to me more?
Thank you.
0
zipe31 Posted messages 34620 Registration date   Status Contributeur Last intervention   6 500
 
After the backslash, you press Enter and continue the rest of the syntax on the next line.
0
bibitun Posted messages 10 Status Membre
 
And what if I have a shell?
0
zipe31 Posted messages 34620 Registration date   Status Contributeur Last intervention   6 500
 
You press <Enter> without the backslash before it ;-)
0
zipe31 Posted messages 34620 Registration date   Status Contributeur Last intervention   6 500
 
Finally no, I may have said something stupid, you do the same with the anti-slash and the <Enter> ;-)
0
bibitun Posted messages 10 Status Membre
 
It worked, but by adding another backslash: \\
Thank you very much for this help, you saved my day! :-)
0