LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-28-2006, 11:38 PM   #1
slack66
Member
 
Registered: Jul 2003
Location: manila
Distribution: slackware 8 to 9
Posts: 199

Rep: Reputation: 30
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

Last edited by slack66; 04-28-2006 at 11:41 PM.
 
Old 04-29-2006, 12:33 AM   #2
tells
Member
 
Registered: Jun 2003
Location: Peoria, IL
Distribution: Ubuntu (home) / RHEL (work)
Posts: 65

Rep: Reputation: 15
I would use awk.

du -sh /projects/disk1/ | awk -F"/" '{print $1, $4}'
 
Old 04-29-2006, 12:35 AM   #3
tells
Member
 
Registered: Jun 2003
Location: Peoria, IL
Distribution: Ubuntu (home) / RHEL (work)
Posts: 65

Rep: Reputation: 15
You could do it with sed too:

du -sh /projects/disk1/ | sed 's#/project/disk1/##g'
 
Old 04-29-2006, 01:46 AM   #4
slack66
Member
 
Registered: Jul 2003
Location: manila
Distribution: slackware 8 to 9
Posts: 199

Original Poster
Rep: Reputation: 30
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
 
Old 04-29-2006, 09:34 AM   #5
dubya
Member
 
Registered: Mar 2004
Location: Kitchener, Ontario, Canada
Posts: 386

Rep: Reputation: 30
I've used sed a lot at work but have never come across #, what does that mean?
 
Old 04-29-2006, 10:21 AM   #6
AdaHacker
Member
 
Registered: Oct 2001
Location: Brockport, NY
Distribution: Kubuntu
Posts: 384

Rep: Reputation: 31
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.
 
Old 04-29-2006, 10:24 AM   #7
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
You might also have used
Code:
(cd /projects/disk1/ && du -sh *)
 
  


Reply

Tags
awk, disk usage, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
More SED help facets Programming 2 06-03-2004 11:02 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Sed help noodle123 Programming 6 04-22-2002 09:08 AM


All times are GMT -5. The time now is 10:02 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration