Line break addition
wida
Posted messages
170
Status
Member
-
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
Hello,
I use this command to get a line break every time I encounter a '+' sign:
sed 's/+/\n/g'
But instead of getting a line break, I have a simple space!! Do you know why? What is wrong with this command?
Thank you for your intervention :-)
--
The dream leads to nothing, action leads to everything.
(J. FIAUX).
I use this command to get a line break every time I encounter a '+' sign:
sed 's/+/\n/g'
But instead of getting a line break, I have a simple space!! Do you know why? What is wrong with this command?
Thank you for your intervention :-)
--
The dream leads to nothing, action leads to everything.
(J. FIAUX).
Configuration: Linux Fedora / Firefox 3.5.1
12 answers
-
Hello,
#!/bin/bash Machines=machine1+machine2+machine3 liste=$(echo $Machines | sed 's/+/\n/g') echo "$liste"
--
106485010510997108 -
Re,
I told you what to do. You need to use quotation marks for the display.
lami20j@debian-acer:~/livres_tutoriaux/pcasm/linux-ex$ cat plus.sh #!/bin/bash Machines=machine1+machine2+machine3 liste=$(echo $Machines | sed 's/+/\n/g') liste2=`echo "$liste"` echo "$liste2" lami20j@debian-acer:~/livres_tutoriaux/pcasm/linux-ex$ sh plus.sh machine1 machine2 machine3
--
106485010510997108-
It's not the display that interests me, but the content of the variable..
--
The dream leads to nothing, action leads to everything.
(J. FIAUX).- In the previous example, I echoed just to check the content of the variable liste2
Here is another example:
allMachine='' for i in 1 4 7 10; do Machines=machine$i+machine$(i+1)+machine$(i+2) liste=$(echo $Machines | sed 's/+/\n/g') allMachine=$allMachine' '$Machines done
The goal is to have the list of all machines in allMachine in order to perform tasks on these machines. So I really have nothing to do with the display; it was just to see the content of the variables
--
The dream achieves nothing, action achieves everything.
(J. FIAUX).
-
-
Hi,
Weird indeed;-\
What's the version of "sed"?
Which shell?
On a Unix file?
--
$ man woman
There is no manual page for woman. -
In fact, I'm starting with Linux and I don't know how to get all this information!!
I run the command from a script, but if I run it directly from the shell there's no problem!
--
The dream leads to nothing, action leads to everything.
(J. FIAUX). -
#!/bin/bash Machines=machine1+machine2+machine3 liste=` echo $Machines | sed 's/+/\n/g'` echo $liste
--
The dream leads to nothing, action leads to everything.
(J. FIAUX). -
In fact, I notice one thing, if I do this:
Machines=machine1+machine2+machine3 echo $Machines | sed 's/+/\n/g'
it works well but the other way of doing it still doesn't work!!
--
The dream leads to nothing, action leads to everything.
(J. FIAUX). -
I really need to put the result in a variable!! I don’t see how to do it without ending up back in the initial case!!
--
Dreaming leads to nothing, action leads to everything.
(J. FIAUX). -
Look at the response from "lami20j", or:
#!/bin/bash Machines=machine1+machine2+machine3 echo -e "${Machines//+/\n}"
--
$ man woman
There is no manual page for woman. -
Merci ça marche bien, mais en fait y a toujours un souci quand j'utilise la variable liste ! Le saut de ligne, je le veux dans la variable, pas juste dans l'affichage
exemple :#!/bin/bash Machines=machine1+machine2+machine3 liste=$(echo $Machines | sed 's/+/\n/g') liste2=`echo "$liste"` echo $liste2
liste2 contient exactement la même valeur que liste
--
Le rêve n'aboutit à rien, l'action à tout.
(J. FIAUX). -
Re,
So you want this?lami20j@debian-acer:~/livres_tutoriaux/pcasm/linux-ex$ cat plus.sh #!/bin/bash Machines=machine1+machine2+machine3 liste=$(echo $Machines | sed 's/+/\\n/g') liste2=$(echo $liste) echo $liste echo -e $liste lami20j@debian-acer:~/livres_tutoriaux/pcasm/linux-ex$ sh plus.sh machine1\nmachine2\nmachine3 machine1 machine2 machine3
--
106485010510997108 -
Re,
so I really have nothing to do with the display, it was just to see the content of the variables
Calm down, okay?!
We are trying to help you and in order to help you, we first need to understand what you want.
For now, I don't see what you want, so I'm just feeling my way around.
If you want to see the content of the variable, then you just need to do it like this, no need for sed
lami20j@debian-acer:~/livres_tutoriaux/pcasm/linux-ex$ cat plus.sh #!/bin/bash Machines=machine1+machine2+machine3 IFS='+' for m in $Machines do echo $m done lami20j@debian-acer:~/livres_tutoriaux/pcasm/linux-ex$ sh plus.sh machine1 machine2 machine3
--
106485010510997108-
Apparently I didn't explain myself well!! So I'll start over,
the variable Machines contains this:Machines=machine1+machine2+machine3
I want the variable list to contain this:list= machine1 machine2 machine3
after the commands I run, I check if my variable list contains what I want, so I do this:
echo $list
this codeecho "$list"
or this one
echo -e $list
gives a perfect display, but doesn't change the content of my variable!! I don't know if it's clearer now!!!
--
The dream leads to nothing, action leads to everything.
(J. FIAUX).
-
-
if you do
$ set|grep list
list=$'machine1\nmachine2\nmachine3'
the variable contains exactly what you want