Line break addition

wida Posted messages 170 Status Member -  
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).
Configuration: Linux Fedora / Firefox 3.5.1

12 answers

  1. lami20j Posted messages 21506 Registration date   Status Moderator, Security Contributor Last intervention   3 571
     
    Hello,

    #!/bin/bash Machines=machine1+machine2+machine3 liste=$(echo $Machines | sed 's/+/\n/g') echo "$liste" 

    --
    106485010510997108
    1
  2. lami20j Posted messages 21506 Registration date   Status Moderator, Security Contributor Last intervention   3 571
     
    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
    1
    1. wida Posted messages 170 Status Member 17
       
      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).
      0
      1. jipicy Posted messages 40842 Registration date   Status Moderator Last intervention   4 898 > wida Posted messages 170 Status Member
         
        The display is only the representative form of interpretation!

        --
        $ man woman
        There is no manual page for woman.
        0
      2. wida Posted messages 170 Status Member 17 > jipicy Posted messages 40842 Registration date   Status Moderator Last intervention  
         
        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).
        0
  3. jipicy Posted messages 40842 Registration date   Status Moderator Last intervention   4 898
     
    Hi,

    Weird indeed;-\

    What's the version of "sed"?
    Which shell?
    On a Unix file?

    --
    $ man woman
    There is no manual page for woman.
    0
  4. wida Posted messages 170 Status Member 17
     
    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).
    0
    1. jipicy Posted messages 40842 Registration date   Status Moderator Last intervention   4 898
       
      So show us your script so we can try to spot what's wrong...

      --
      $ man woman
      There is no manual page for woman.
      0
  5. wida Posted messages 170 Status Member 17
     


    #!/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).
    0
  6. wida Posted messages 170 Status Member 17
     
    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).
    0
  7. wida Posted messages 170 Status Member 17
     
    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).
    0
    1. lami20j Posted messages 21506 Registration date   Status Moderator, Security Contributor Last intervention   3 571
       
      Re,

      Look at answer 6
      --
      106485010510997108
      0
  8. jipicy Posted messages 40842 Registration date   Status Moderator Last intervention   4 898
     
    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.
    0
  9. wida Posted messages 170 Status Member 17
     
    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).
    0
  10. lami20j Posted messages 21506 Registration date   Status Moderator, Security Contributor Last intervention   3 571
     
    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
    0
  11. lami20j Posted messages 21506 Registration date   Status Moderator, Security Contributor Last intervention   3 571
     
    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
    0
    1. wida Posted messages 170 Status Member 17
       
      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 code
      echo "$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).
      0
  12. dubcek Posted messages 18627 Registration date   Status Contributor Last intervention   5 660
     
    if you do
    $ set|grep list
    list=$'machine1\nmachine2\nmachine3'
    the variable contains exactly what you want
    0