1819850 Members
2660 Online
109607 Solutions
New Discussion юеВ

Re: the sed command

 
SOLVED
Go to solution
vaman
Frequent Advisor

the sed command

I am trying one command
ls -ld /dev/vg_rdo1_s_rac_dbf0* | awk '{print $9}'
The o/p is
/dev/vg_rdo1_s_rac_dbf01/
/dev/vg_rdo1_s_rac_dbf02/
/dev/vg_rdo1_s_rac_dbf03/
/dev/vg_rdo1_s_rac_dbf04/
/dev/vg_rdo1_s_rac_dbf05/
/dev/vg_rdo1_s_rac_dbf06/
/dev/vg_rdo1_s_rac_dbf07/

I want to remove the last / from above output so i can run vgdisplay in loop. I would like to know how sed can be used to carry out this activity
vaman kulkarni
6 REPLIES 6
c_51
Trusted Contributor
Solution

Re: the sed command

just

awk '{print $9}' |
sed 's!/$!!'


Denver Osborn
Honored Contributor

Re: the sed command

With your syntax, ls on hpux doesn't put the trailing slash if it is a dir unless you specify -p option. Do you have ls aliased?

try

/usr/bin/ls -ld /dev/vg_rdo1_s_rac_dbf0* | awk '{print $9}'


-denver
Todd McDaniel_1
Honored Contributor

Re: the sed command

This will work...

for name in `ls -ld /dev/vg_rdo1_s_rac_dbf0*|awk -F\/ '{ print $X }' `
do
vgdisplay /dev/$name
done > outputfile.out


Where the $X is equal to the field number using / as a delimeter...
Unix, the other white meat.
Matthew_50
Valued Contributor

Re: the sed command

cd /dev
for i in `ls -d vg_rdo1_s_rac_dbf0*`
do
vgdisplay $i
done
Rory R Hammond
Trusted Contributor

Re: the sed command

AWK supports regular expressions like sed the sub will remove the last /

Rory

ls -ld /dev/vg_rdo1_s_rac_dbf0* | awk '{sub("/$","",$9)
print $9 }'
There are a 100 ways to do things and 97 of them are right
baiju_3
Esteemed Contributor

Re: the sed command

Hi Vaman,

Just do "l -ld /dev/vg*" instead of ls -ld .



Regards,
BL.
:)
Good things Just Got better (Plz,not stolen from advertisement -:) )