Operating System - HP-UX
1836987 Members
2208 Online
110111 Solutions
New Discussion

Re: remove leading character

 
SOLVED
Go to solution
John Roy Arendain
New Member

remove leading character

Please advise what command do I use to remove the leading character "%" from the output of command "bdf â l | awk â {print $5}â "
7 REPLIES 7
Michael Steele_2
Honored Contributor
Solution

Re: remove leading character

'^' for leading character.

Maybe:

# sed 's/^//g' filename

Try this handy SED URL:

http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html
Support Fatherhood - Stop Family Law
Bill Hassell
Honored Contributor

Re: remove leading character

Or you can use tr:

bdf | tr "%" " " | awk '{print $5}'


Bill Hassell, sysadmin
Rajeev  Shukla
Honored Contributor

Re: remove leading character

Use
bdf|awk '{print $5}'|sed 's/%//g'
Rajeev  Shukla
Honored Contributor

Re: remove leading character

And if you want %used to be left as it is try

bdf|awk '{print $5}'|sed 's/%$//g'
John Roy Arendain
New Member

Re: remove leading character

Thanks Guys! our File system monitoring script is now complete. I am attaching the script file.
Duncan Galbraith
Frequent Advisor

Re: remove leading character

The bdf line in your script will only work for short filesystem names. Perhaps you are lucky and only have short names but on many systems the output of bdf for a filesystem often covers 2 lines so your bdf line might be better something like:
bdf ${FS[$i]} | grep " ${FS[$i]}$" | awk '{ print $(NF-1) }' | sed 's/%//'
Graham Cameron_1
Honored Contributor

Re: remove leading character

And if you want to combine Duncan's fix to cope with > 1 line, and avoid grep and sed, doing it all with awk in one shot, how about.

bdf ${FS[$i]} |awk '/^Filesystem/ {next} (NF==1) {getline} {print substr($(NF-1),1,length($(NF-1)-1))}'

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.