LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed questions (https://www.linuxquestions.org/questions/linux-newbie-8/sed-questions-439897/)

slack66 04-28-2006 11:38 PM

sed questions
 
hi:)

i just want to monitor my disk usage by using du command : du -sh /projcts/disk1/
the result:

235M (space) /projects/disk1/firstproject
564M (space) /projects/disk1/secondproject
1.5G (space) /projects/disk1/thirdproject

and so on....
but i just want to eliminate all the /project/disk1/


235M (space) firstproject
564M (space) secondproject
1.5G (space) thirdproject


can i use sed to reformat the output of DU command??
please help me thank in advance:)

tells 04-29-2006 12:33 AM

I would use awk.

du -sh /projects/disk1/ | awk -F"/" '{print $1, $4}'

tells 04-29-2006 12:35 AM

You could do it with sed too:

du -sh /projects/disk1/ | sed 's#/project/disk1/##g'

slack66 04-29-2006 01:46 AM

hi tells:)

thank for your quick solution to my problem:) now i can monitor my disk usage without the long path file.... THANK! Big help for me:)

dubya 04-29-2006 09:34 AM

I've used sed a lot at work but have never come across #, what does that mean?

AdaHacker 04-29-2006 10:21 AM

Quote:

Originally Posted by dubya
I've used sed a lot at work but have never come across #, what does that mean?

It's simply an alternate way of writing a standard substitution. Sed allows you to use characters other than / as delimiters in substitution expressions. So, for example, 's#/home/me/##', 's|/home/me/||', and 's/\/home\/me\///' are all equivalent. The first two are just cleaner and easier to read if your match expression has slashes in it.

uselpa 04-29-2006 10:24 AM

You might also have used
Code:

(cd /projects/disk1/ && du -sh *)


All times are GMT -5. The time now is 03:31 PM.