Can you please break up this command and explain it to me. I am completely new to unix and don't understand it. But it has worked flawlessly.
Lets start with the first part:
basically it executes "w" (see the man page of "w" for details) and pipes the output of it to "tail". You might want to read the man page of "tail" too, but in fact it displays a number of lines from some file or output stream - counted from the end. "tail -1" would display the last line, "tail -3" the last 3 lines, etc..
Instead of a fixed number like "1" or "3" an expression is used, which resolves to such a number:
The "$(( ... ))" is just a device to make what comes out of the command inside part of the original line. Inside this there is another (numeric) expression: "<something> - 2". So we first have to examine what "something" does:
This calls again "w" and pipes its output to "wc". "wc" stands for "word count", with the "-l" parameter it counts lines instead of words. So we have:
Count the lines of "w"s output (innermost expression), then subtract 2 from it. This is the content of "$(( ... ))": the number of lines "w"s output has, minus 2.
At last we use this number as the parameter of "tail", so all lines from "w"s output, minus 2 lines, are printed. As "tail" (you remember?) outputs always the lastmost lines this
means: print all output of "w" save for the first two lines. This makes sense because the first two lines are header information and you donÄt want to use them.
Now lets see what is done with this output:
"tee" is a command you use to duplicate output streams. A UNIX command usually works like a garden hose: you put something in, it does doemthing with it inside, then something comes out. But once you direct this stream to some direction (like another command, a file, whatever) you can't use it anywhere else. This is what "tee" is for: it makes two (identical) streams out of one, so you can use both. The first stream is not processed at all so it is displayed as it is. Try it out (command up to "| tee ...") and you will recognize the part ot the output.
The other stream is directed at
If first is directed at "cut", which cuts lines into "fields" (as always, i suggest you read the man page). In this case the delimiter character "blank" is selected "-d\ " (you have to precede special characters with "\") and "cut" is told we want only the first "field" (fields are parts of the line separated by the delimiter characters: "cut -d'|' -f3" would yield "3" of "a|b|3|4|x|y").
So, after mangling the output through "cut" it is reduced to the first word in the line, which is the users name. Next comes a command named "uniq", which filters out all the duplicates. If a user has several sessions open he would show up with several lines here and "uniq" takes care of that.
Finally, the so processed output is further processed by "wc -l", which i have explained above already - it yields the number of lines. This number is then displayed at "stderr", which means in this case it is displayed below the other output so far. Try the command
and you will see only this part of the output.
I hope this helps.
bakunin
These 3 Users Gave Thanks to bakunin For This Post:
Hello,
I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is
sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name3>' |... (0 Replies)
Hello,
I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is
sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name3>' |... (1 Reply)
Hi everybody..
I need to enter in bash mode and then run a command and this just in a single command line.
I tried : "bash ^M| somecommand" but nothing..
How do I do to simulate the return button just right after the bash command ?
Thanks.. (8 Replies)
Hi
I want to display "echo command value in loop" in single line. My requirement is to show the input file (test_1.txt) like the output file (test_2.txt) given below.
Input file :test_1.txt
a1|b1|4|5
a1|b1|42|9
a2|b2|32|25
a1|b1|2|5
a3|b3|4|8
a2|b2|14|6
Output file:test_2.txt... (2 Replies)
Hi ,
Can You Please let Know How use unix uniq command on a single column for deleting records from file
with Below Structure.Pipe Delimter File .
Source
Name | Account_Id
A | 101
B... (2 Replies)
Hello Experts,
I have a log file that contains 4 different type of exception :
1- Exception
2- Fatal
3- Error
4- Exec
My requirement is to find count of each type of exception, i tried using combination of -E and -C but that doesn't seems to be working :
grep -ec 'Exception' -ec... (4 Replies)
Hi,
I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output
Here is how my file looks like
1.1.1.1
1.1.1.2
1.1.1.3
1.1.2.1
1.1.2.2
1.1.3.1
1.1.3.2
1.1.3.3
1.1.3.4
So what I am trying... (2 Replies)