1826490 Members
3630 Online
109692 Solutions
New Discussion

Re: awk,trap,sed

 
SOLVED
Go to solution
Alice_4
Occasional Advisor

awk,trap,sed

can anyone please explain to me what are these mean?

1)`awk -F: '$6 == "'$serial'" {print $2}' database`"

2)trap '' 1 2 3 18

3)sed "/$cserial/d" database > delete

thank you very much...
5 REPLIES 5
Robin Wakefield
Honored Contributor
Solution

Re: awk,trap,sed

Alice,

1) split each line in "database" at the ":" character, and print the 2nd field if the 6th field is the value of $serial

2) ignore signals 1, 2, 3, 18

3) delete any lines containing the $cserial variable, and output the remaining lines to the file delete.

Rgds, Robin.
Ralph Grothe
Honored Contributor

Re: awk,trap,sed

1) parse file database, and take the colon ':' as field separator, then print the 2nd field whenever the 6th field equals the value of the value variable $serial holds.

2) reset the default behaviour to signals 1 (SIGHUP), 2 (SIGINT), 3 (SIGQUIT), 18 (SIGCHLD),
assumably because a signal handler for these signals was defined earlier in the script

3) from file database delete every line where the contents of variable $cserial matches, and redirect output to file delete
Madness, thy name is system administration
Jean-Louis Phelix
Honored Contributor

Re: awk,trap,sed

Sorry Ralph, but Robin is right (perhaps Alice could give him points ???).

1 - OK

2 - IGNORE signals ... To restore to default handling you should have nothing between 'trap' and signals list (no '')

3 - Only remaining lines are redirected to output file.

Regards.
It works for me (© Bill McNAMARA ...)
Ralph Grothe
Honored Contributor

Re: awk,trap,sed

Yes Jean-Loius,

you both were right of course.

I simply mistook it because I hardly ever set traps in shell scripts anymore but instead use Perl whenever I have to implement a signal handler somewhere, where you simply could say something like

$SIG{HUP} = $SIG{INT} = $SIG{QUIT} = $SIG{CHLD} = 'IGNORE';


Sorry, if I had noticed that Robin already has posted a reply I definitely wouldn't have responded at all.
So I guess we had a kind of race condition here.
Madness, thy name is system administration
Alice_4
Occasional Advisor

Re: awk,trap,sed

thank you guys..all of you really do help me a lot with the answers you all gave to me...