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 ...
- 01-16-2009 #1Just 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!
- 01-16-2009 #2Linux 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.
- 01-20-2009 #3
good resource ... good coders code, great reuse


Reply With Quote