1834757 Members
2888 Online
110070 Solutions
New Discussion

What is the output

 
SOLVED
Go to solution
panchpan
Regular Advisor

What is the output

Please suggest, what is the significance of:

grep "^d"
grep "d[0-9]"
\ after 2nd grep
awk '{print $3}'

for DSTUFF in `cat $STFILE | grep "^d" | grep "d[0-9]" | \
sed -e's/\"Schema Area\"/\"Schema_Area\"/' | awk '{ print $3}'`

Thank you!
7 REPLIES 7
Pete Randall
Outstanding Contributor

Re: What is the output

You might want to spend some time with the man pages for regexp(5) and grep(1).


Pete

Pete
Oviwan
Honored Contributor

Re: What is the output

Hey

Do you mean the backslash (\)?
with the \ you can write a command on two line you could also write the command like this:

for DSTUFF in `cat $STFILE | grep "^d" | grep "d[0-9]" | sed -e's/\"Schema Area\"/\"Schema_Area\"/' | awk '{ print $3}'`

Hope this helps..

Regards
James R. Ferguson
Acclaimed Contributor

Re: What is the output

Hi:

The backslash denotes a line continuation allowing the pipeline to be written across two lines.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor
Solution

Re: What is the output

Hi (again):

...or are you asking about each listed item?

1. The caret (^) anchors the match of the "d" to the beginning of a line.

2. The [0-9] means match any number from 0 to 0.

3. The "\" is a line continuation character when it occurs after the second 'grep' allowing the pipeline to be written on two lines. The use of the backslash ('\') in the 'sed' command is to escape the double quote character and thus tell 'sed' to treat it as part of its match and substitute.

4. The 'awk' statement is printing the third (counting from one) field of whitespace delimited fields in the data stream it receives from the pipe.

Regards!

...JRF...
panchpan
Regular Advisor

Re: What is the output

THANKS A LOT
Hein van den Heuvel
Honored Contributor

Re: What is the output


btw... you de realize that is a disgusting piece of work right?

for DSTUFF in `cat $STFILE | grep "^d" | grep "d[0-9]" | sed -e's/\"Schema Area\"/\"Schema_Area\"/' | awk '{ print $3}'`

If uses 5 images and 4 processes for a job which awk or perl can do in s single pass.

In perl (untested)

perl -lne 'if (/^d/ && /d[0-9]/) { s/Schema Area/Schema_Area/; print (split)[2]' $STFILE

I also suspect that the d[0-9] is likely to trigger on the same d at the start of line and that the substitue effectively only reduced the colun count. The whole script migth reduce to:

awk '/^d[0-9]/{ print $4 }' $STFILE

Regards,
Hein.
Dennis Handly
Acclaimed Contributor

Re: What is the output

Note you didn't need to have that "\" at the end of the line since "|" causes the shell to keep reading.

>Hein: The whole script migth reduce to:
awk '/^d[0-9]/{ print $4 }' $STFILE

You don't know about $4 since it may need that sed(1) to change some of the lines so it gives a consistent $3.