substr (32 Views)
Regular Advisor
A.G.M. Velthof
Posts: 201
Registered: ‎02-18-2002
Message 1 of 5 (32 Views)
Accepted Solution


Hello all,

I am making a script to determinate a filesystem from the cmviewcl command.
I've come this far.

uname -a|awk '{print $2}'>NODE_NAME
cmviewcl -n $NODE|grep -e running|grep -e NAO|awk '{print $1}' > running.out (this produces the file "running.out" with 2 entry's, NAOT01 and NAOT03)
How do I change it, so the script substracts it to a file with the entry's T01 an T03?

Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 5 (32 Views)

Re: substr


Do you want something like:

# echo "NAT01\nNAT03"|awk '{print substr($1,3)}'

...this snips off the first three characters of the string in $1.


Please use plain text.
Honored Contributor
Mel Burslan
Posts: 3,212
Registered: ‎08-26-1998
Message 3 of 5 (32 Views)

Re: substr

you can pipe your output to

| cut -c4-

but this only works if you have 3 leading characters bedore the Txx string in the nodenames.

UNIX because I majored in cryptology...
Please use plain text.
Regular Advisor
A.G.M. Velthof
Posts: 201
Registered: ‎02-18-2002
Message 4 of 5 (32 Views)

Re: substr

Thanks, both solutions work.

Regards, Alfons
Please use plain text.
Trusted Contributor
Rory R Hammond
Posts: 302
Registered: ‎07-21-1999
Message 5 of 5 (32 Views)

Re: substr

NODE=$uname -a |awk '{print $2}')
cmviewcl -n ${NODE} |
awk '($0 ~ /running/ && $1 ~ /NA/) { print substr($1,3)}
There are a 100 ways to do things and 97 of them are right
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation