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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed syntax 1

Status
Not open for further replies.

unixwhoopie

Programmer
May 6, 2003
45
US
Can someone tell what this does? what is the significance of w and '/'?

sed -n '/'${TIMESTAMP}'/w '${RES_FILE} ${SRVLOG}

thanks
 
Hello,
It appears that this line is lifted from a Korn shell script although it could also be Bourne. In it the sed command is configured not to write to standard output(the -n). sed is getting its input from the file represented by the variable ${SRVLOG} and that sed is writing the line matches from the variable ${TIMESTAMP} to the file represented by the variable ${RES_FILE} (the '/w ' and '/' are syntax wrappers for the timestamp line search). The entire command should be extracting lines with a particular timestamp from a syslog file(or something similar) and creating an output file with these line matches.
By converting the 'code' to an example command it might be easier to see how the command is set up.
sed -n /200301011200/w residual.file /var/log/syslog
Hope this helps!
Charlie Ehler
 
Hello,
My mistake! The '/' and '/w ' prevent command garbled errors.
Anyway the correct sed format(that works in solaris 2.5.1) is:
sed -n '/'match string'/w 'output_file input_file
Why this is correct is beyond me, since the man pages don't seem to indicate this.
Later!
Charlie Ehler
 
It's not on the sed man page because it's a shell feature. The whole sed command needs to be recognised as one parameter, and if you don't have the quotes the space between "/w" and "output_file" split the command into two parts, and the first part is no longer a complete sed command, hence "command garbled".

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top