1833876 Members
1653 Online
110063 Solutions
New Discussion

Re: awk string

 
SOLVED
Go to solution
Rene Mendez_4
Super Advisor

awk string

I have one file name: cpu_stat_oct152003

i need on script cut cpu_stat because my new file is : saroct152003,

how to.

Regards
Rene
2 REPLIES 2
Hein van den Heuvel
Honored Contributor

Re: awk string


Your question is not entirely clear to me.
If you need to transform the first string
into the second then here are a few examples:


echo cpu_stat_oct152003 | awk -F_ '{print "sar" $3}'

echo cpu_stat_oct152003 | awk '{split ($0,words,"_"); print "sar" words[3]}'

echo cpu_stat_oct152003 | awk '{sub("cpu_stat_","sar"); print}'

hth,
Hein.
curt larson_1
Honored Contributor
Solution

Re: awk string

or without even using awk

oldname="cpu_stat_oct152003"
newname="sar${oldname##*_}"