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!

what the following command is doing ?

Status
Not open for further replies.

mikelala1973

Technical User
Dec 3, 2013
1
0
0
US
Plesae let me know what the following command is doing ..

Could not able to understand ..

print $(wc -l $InputFileSrc | awk '{ print $2 "|"$1 "|" }')$(cksum $InputFileSrc | awk '{ print $1 }') | awk -F"[ /]" '{ print $NF }'

thanks/Mike
 

Code:
print $( -- Prints the following (string):
wc -l $InputFileSrc            <--count lines in $InputFileSrc file
| awk '{ print $2 "|"$1 "|" }' <--piped into awk which will concat and print $2=file name, '|', line count
) concatenated to the following string:
$(
cksum $InputFileSrc |           <-- checksum of same file piped into awk
awk '{ print $1 }') |           <-- which prints the first field, ends the string and pipes into...
awk -F"[ /]" '{ print $NF }'    <-- which sets the input field separator to space+/ and 
                                    prints the number of fields.
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

PS: This part does nothing because the resulting string has no spaces or '/'s:
Code:
.... | awk -F"[ /]" '{ print $NF }'


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

it just echo two $(...)

Code:
# InputFileSrc=file
# print $(wc -l $InputFileSrc | awk '{ print $2 "|"$1 "|" }')$(cksum $InputFileSrc | awk '{ print $1 }') | awk -F"[ /]" '{ print $NF }'
file|2|3115234434
#

and step by step:

Code:
# wc -l $InputFileSrc
       2 file
# wc -l $InputFileSrc | awk '{ print $2 "|"$1 "|" }'
file|2|
# print $(wc -l $InputFileSrc | awk '{ print $2 "|"$1 "|" }')
file|2|
# cksum $InputFileSrc
3115234434 8 file
# cksum $InputFileSrc| awk '{ print $1 }'
3115234434
# print $(cksum $InputFileSrc | awk '{ print $1 }')
3115234434
# print "file|2|3115234434"
file|2|3115234434
# print "file|2|3115234434"|awk -F"[ /]" '{ print $NF }'
file|2|3115234434
#

so the last piped awk has nothing to do in above sample, but in below input it does

Code:
# InputFileSrc=/tmp/dd/file
# print $(wc -l $InputFileSrc | awk '{ print $2 "|"$1 "|" }')$(cksum $InputFileSrc | awk '{ print $1 }')
/tmp/dd/file|2|3115234434
# printf "/tmp/dd/file|2|3115234434" | awk -F"[ /]" '{ print $NF }'
file|2|3115234434
#


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top