LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-21-2003, 03:10 PM   #1
rajatgarg
Member
 
Registered: Oct 2003
Posts: 41

Rep: Reputation: 15
grepping last word of output


Hi all,

I am trying to write a script in perl.
It executes df -h and reads the input :
/dev/sda7 688M 45M 608M 7% /scratch
/dev/sda3 981M 17M 915M 2% /tmp
/dev/sda8 494M 282M 187M 61% /usr/vice/cache
/dev/sda5 981M 69M 862M 8% /var

I want to get input in an array ,
where it contains only last field namely -> /scratch, /tmp, /usr/vice/cache, /var

@arr = <xyz>;
takes the whole line as input and I can parse it. But when partition names vary from machines to machines, that ofcourse is not a good idea.

Kindly suggest what to do ???

Regards,
Rajat Garg
SU
 
Old 11-21-2003, 03:37 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I beleive this should work for what you want:
Code:
#!/usr/bin/perl
@array=split(/\n/,`df`);
for ($done=1; $done<@array; $done++){
@fields=split(/\s/,$array[$done]);
$array[$done]=$fields[@fields-1];
print $array[$done]."\n";
}
exit;
 
Old 11-25-2003, 08:34 AM   #3
inTrouble?
LQ Newbie
 
Registered: Oct 2003
Posts: 5

Rep: Reputation: 0
you can start with

df | cut -c57-


Last edited by inTrouble?; 11-25-2003 at 08:35 AM.
 
Old 11-25-2003, 10:41 AM   #4
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
df -h | awk '{ print $NF }'
 
  


Reply


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
grepping unknown text, is there a way? vdemuth Programming 15 09-26-2005 03:00 AM
Question about referring a word in a command output aaronshi *BSD 2 05-14-2005 10:47 PM
question about grepping something Grafbak Programming 6 03-01-2005 01:28 PM
Not grepping emails right mikeyt_333 Linux - General 11 04-13-2003 02:48 PM
grepping for multi-line output born4linux Programming 1 03-07-2003 02:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:24 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration