Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

substr

SOLVED
Go to solution
A.G.M. Velthof
Valued Contributor

substr

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
read NODE<$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?

Thanks
4 REPLIES
James R. Ferguson
Acclaimed Contributor
Solution

Re: substr

Hi:

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.

Regards!

...JRF...
Mel Burslan
Honored Contributor

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...
A.G.M. Velthof
Valued Contributor

Re: substr

Thanks, both solutions work.

Regards, Alfons
Highlighted
Rory R Hammond
Trusted Contributor

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