- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Matching specific word and fetch the value ass...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 01:01 AM
тАО04-06-2011 01:01 AM
I need to match the exact words like /clocal, /clocal/dba in the below file and fetch the corresponding values present next to those words.
shcscp19:/ $ cat /tmp/test.txt
/clocal 5
/clocal/dba 10
/clocal/ora 15
/clocal/mqm/user/mqm 20
I used grep -w option but its fetching all filesystems starting with /clocal like below.
shcscp19:/ $ grep -w /clocal /tmp/test.txt
/clocal 5
/clocal/dba 10
/clocal/ora 15
/clocal/mqm/user/mqm 20
I tried ^$ option like below, but failed to fetch the value.
shcscp19:/ $ grep ^/clocal$ /tmp/test.txt
shcscp19:/ $
Please help me to match the exact word and get the corresponding value mentioned for that filesystem.
Thanks,
Ram.
Solved! Go to Solution.
- Tags:
- match
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 01:30 AM
тАО04-06-2011 01:30 AM
Re: Matching specific word and fetch the value assigned to that
# sed -n -e 's#/clocal .*#&#p' -e 's#/clocal/dba .*#&#p' /tmp/test.txt
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 01:33 AM
тАО04-06-2011 01:33 AM
Solutionthe main idea is to match not to "/clocal" but to "/clocal ". so this should also work:
# grep "/clocal " /tmp/test.txt
With "-w" it does not work on my test linux system, currently I don't have access to an HP-UX.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 01:43 AM
тАО04-06-2011 01:43 AM
Re: Matching specific word and fetch the value assigned to that
>I need to match the exact words like /clocal, /clocal/dba ..
- Why to get it from the file , as these are filesystem why not to use directly from bdf command to capture a filesystem, like:
# bdf /clocal
or
# bdf /clocal/dba
Hth,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 01:53 AM
тАО04-06-2011 01:53 AM
Re: Matching specific word and fetch the value assigned to that
Thanks, I checked grepping /clocal with space as you mentioned and it seems to be working. I need to configure the same in script for multiple filesystems. I will execute and let you know how it goes.
Thanks,
Ram.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 01:55 AM
тАО04-06-2011 01:55 AM
Re: Matching specific word and fetch the value assigned to that
User want to monitor only required filesystems from a file with a threshold value... Thats the reason for reading it from a file.
Thanks,
Ram.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 02:33 AM
тАО04-06-2011 02:33 AM
Re: Matching specific word and fetch the value assigned to that
in this case I would rather use two arrays, and fill these with the values fetched directly from the config file. (test.txt)
#reading in the values to an array:
i=0
while read fs treshold
do
FS[$i]=$fs
TRESH[$i]=$treshold
(( i+=1 ))
done < /tmp/test.txt
echo $i items has been loaded from the config.
this way you would end up with two arrays: FS[] containing the filesystems to be monitored, and TRESH[] for the corresponding tresholds. The relation to these two is the common index for a specific filesystem.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2011 03:43 AM
тАО04-06-2011 03:43 AM
Re: Matching specific word and fetch the value assigned to that
> Please help me to match the exact word and get the corresponding value mentioned for that filesystem.
You could do:
# perl -le '$m=shift;while (<>) {m{$m\s+(\d+)} and print $1}' /clocal /tmp/test.txt
5
# perl -le '$m=shift;while (<>) {m{$m\s+(\d+)} and print $1}' /clocal/ora /tmp/text.txt
15
This matches the string you pass as the first argument in the file passed as the second argument. A match occurs if the string sequence is found, followed by one or more spaces, followed by one or more digits. When thus matched, the digit(s) are captured and printed.
Regards!
...JRF...