bash script

#1 What does the following command line do ?
awk '{print $1}' | sort -k1 | uniq -c | sort -nk1 | gawk '{if ($1>ENVIRON["THRESHOLD"]){print}}'

#2 gawk '$10 ~ /^[0-9]*$/ { SUM += $10} END { print sprintf("%.0f", SUM/1024/1024)}'  
grep "\" 200" | awk '$10 > 10000 {print}'
AXISHKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
The first command extracts the first space- or tab-delimited filed of each input line. The result is then sorted,  duplicates get removed (uniq), then it's sorted again, this time numerically.
The result is then fed to gawk which checks if the content of the  input field is greater that what's stored in the shell's environment variable "THRESHOLD".
If so, the result (whole line, but it should contain just one field) is printed out.
You don't show where the input comes from, a file or stdin.

The second command checks whether the 10th space- or tab-delimited field of each input line contains just digits 0-9 or nothing (!)
If so, the content of that field is added up in the awk variable "SUM".
When all lines are processed the result is displayed, formatted with no decimal places and divided by 1048576.
Again, you don't show where the input comes from, a file or stdin.


The third command is not connected to the second command (or did you forget to type a pipe "|" symbol`?)
If there is no pipe then once again, you don't show where the input comes from, a file or stdin.
Anyway, something is searched for the string " 200
If found the whole line containing it is fed to awk which checks the 10th space- or tab-delimited field of each input line
if it's content is greater than 10000. If so, the whole line is printed.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
#2 seems to look in a web server log for files/pages served that are greater than 10000 bytes.
0
AXISHKAuthor Commented:
for gawk '$10 ~ /^[0-9]*$/,

is there any special meaning  for ~ & ^  ?  Tks
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Gerwin Jansen, EE MVETopic Advisor Commented:
^ is beginning of the line
$ is end of the line
0
AXISHKAuthor Commented:
* mean one or more occurence , correct ?
what does  ~ mean ?

Tks
0
woolmilkporcCommented:
Not correct. "*" means "no or more occurrences"!

That's why I wrote "the 10th space- or tab-delimited field of each input line contains just digits 0-9 or nothing (!)"

You should use '+' instead of '*' to indicate that the preceeding expression should be matched at least once.

The tilde "~" performs a regular expression comparison, as opposed to "==" which performs an exact string or numerical comparison
0
AXISHKAuthor Commented:
last query, how about ~ ?? Tks
0
Gerwin Jansen, EE MVETopic Advisor Commented:
Yes, I think your pattern is supposed to filter lines with field 10 containing numbers. I would leave out the ^ and $ as well for the filter to work. So something like:

 gawk '$10 ~ /[0-9]*/,

give it a try I would say.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
~ (tilde) means that the pattern between // is treated as a regular expression (RE).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AXISHKAuthor Commented:
Tks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.