Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed syntax help 1

Status
Not open for further replies.

unixwhoopie

Programmer
May 6, 2003
45
0
0
US
I am trying to understand sed but this seems to be very confusing to me. What is the best way to learn sed?

I am trying to debug a program and not sure what the following lines of code mean -

export ARGS=`echo $line | sed 's/,/" "/g'`
ARGS=`echo $ARGS | sed 's/^/"/'`
ARGS=`echo $ARGS | sed 's/$/"/'`


Thanks for the help
 
The first line replaces every comma with a quote-space-quote sequence in the contents of $line. The second line places quote at the first position, as marked by the ^ in the sed script. The third line place a quote at the end position, as marked by the $.

The could easily be condensed to one line:
Code:
export ARGS=`echo $line | sed 's/,/" "/g;s/^/"/;s/$/"/'`

As for learning the web has quite a bit. Do a search on 'sed one liners'. Work with examples and tutorials on sed. I'm sure folks could jump in here - maybe with a good FAQ. Also, read and re-read 'man sed' at every stage of learning - the best reference, but hard to learn from.

Cheers,
ND [smile]

[small]bigoldbulldog AT hotmail[/small]
 
The O'Reilly "sed & awk" book is pretty good. That's one of the books with an animal on it. The "sed & awk" has a pair of slender lorises on the front, and I believe their names are supposed to be "sed" and "awk".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top