Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I am reading a command in shell script using sed: echo $1 | sed -e "s/^[^=]*=\(.*\)$/
/" what I don't understand is the sed command. I only know it tries ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    8

    How to understand this sed command

    Hi,
    I am reading a command in shell script using sed:
    echo $1 | sed -e "s/^[^=]*=\(.*\)$/\1/"

    what I don't understand is the sed command. I only know it tries to substitute "^[^=]*=\(.*\)$/" with "\1" and 1 is one of the positional parameters got from invoking the shell script, but have little idea about what the two things are.

    Thanks for help!

  2. #2
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    658
    ^ Match the beginning of the line
    [^=]* match zero or more characters that aren't "="
    = match "="
    \( identify this bit for \1
    .* match zero or more of anything
    \) end the identified bit.

    So it is looking for the first = sign in the input and removing everything before it.

    Code:
    chris@angua:~$ echo "abc=123" | sed -e "s/^[^=]*=\(.*\)$/\1/"
    123
    chris@angua:~$ echo "abc=123=xyz" | sed -e "s/^[^=]*=\(.*\)$/\1/"
    123=xyz
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

  3. #3
    Just Joined! sathiya's Avatar
    Join Date
    Feb 2008
    Location
    Bangalore, India
    Posts
    97
    good resource ... good coders code, great reuse

Posting Permissions

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