This is a discussion on cut script within the Shell scripting forums, part of the Development/Scripting category; Hi all, I want to write a script that will use the o/p from another utility and act upon a ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
Hi all,
I want to write a script that will use the o/p from another utility and act upon a certain field from the third line onwards Lets suppose, the who command o/p contained a few unwanted lines in the beginning. Like this #who this is the output of the who commnd the users cuttently logged in are root pts/0 Aug 9 14:55 (172.17.0.1) root pts/1 Aug 9 15:58 (172.17.0.1) Now suppose, I want to act upon the fist field, i.e. (usernames in this case) If I write the script as #for i in `who |cut -f1 -d" "`; do echo "these are the users logged on : $i ";done This will also output --this and the But I don't want "this and the". So what shall I do so that it escapes the 1st and 2nd lines and starts acting on the 1st field from the 3rd line onwards till the last one. Can any one please tell me how to do this. Thanks in advance for any help. rc |
| Sponsored Links | ||
|
|
|
||||
|
Hmm
Quite esay I guess Code:
for i in $(who |cut -f1 -d" "|grep -vE "(this|the)" ); do echo "these are the users logged on : $i ";done
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
|
|||
|
Thank you Rocky,
I knew you would certainly reply. Thank you for the solution. I also want to know what if the o/p of who is like this Code:
# who these are the users who are currently logged in ------------------------------------------------------- ram :0 Aug 10 11:27 (console) ram pts/0 Aug 10 11:57 (192.168.2.50) these ------------------------------------------------------- ram ram Now tell me how do I isolate the ------------------------------------------------------- I depend on you rocky. I believe you can help me. Cheers rc |
|
||||
|
It is same as above, here is what you need to first one:
Code:
for i in $(who |cut -f1 -d" "|grep -vE "(^-|this|the)" ); do echo "these are the users logged on : $i ";done
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |