Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    sed split string


    Greetings,
    i have a string that looks like

    Network "123" "ABC"

    i need to make it look like:

    Network "123"
    Network "ABC"

    Help please?
    Thanks again

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    4,031
    Code:
    foo='Network "123" "ABC"'
    
    awk '{print $1" "$2"\n" $1" "$3}' <<< $foo
    Network "123"
    Network "ABC"
    You must always face the curtain with a bow.

  3. #3
    -->
    based on Irithori 's answer, using sed:
    Code:
    $ foo='Network "123" "ABC"'
    $ sed 's/\([^ ]*\) \([^ ]*\) \(.*\)/\1 \2\n\1 \3/' <<<"$foo"
    Network "123"
    Network "ABC"
    bash's way:
    Code:
    read one two three <<<"$foo"
    printf '%s %s\n' "$one" "$two" "$one" "$three"

$spacer_open
$spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •