- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Grepping pattern from a File
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
Forums
Discussions
Discussions
Discussions
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
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
10-02-2006 08:45 PM
10-02-2006 08:45 PM
I want to grep a particular pattern from a file...
The string will be like this...
multimediaGroup type="media" dbid="525"
I want to grep the dbid value say 525 from the file ...
How can I do it with sed or perl..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 08:47 PM
10-02-2006 08:47 PM
Re: Grepping pattern from a File
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 08:54 PM
10-02-2006 08:54 PM
Solutionif your input file format is consistent:
cat input.dat | grep dbid | awk -F'"' '{print $4}'
Please also start rewarding answers to your questions:
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 08:59 PM
10-02-2006 08:59 PM
Re: Grepping pattern from a File
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 09:04 PM
10-02-2006 09:04 PM
Re: Grepping pattern from a File
grep is grep:
grep "dbid=\"[0-9][0-9][0-9]\"$" /your_infile
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 09:08 PM
10-02-2006 09:08 PM
Re: Grepping pattern from a File
Its working fine..
But One more query,
Can we save the value in a variable..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 09:27 PM
10-02-2006 09:27 PM
Re: Grepping pattern from a File
Your solution works but We cant able to assign the value we grepped to the variable..
Can u guide to me how to do the same.
Thanks...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2006 10:23 PM
10-02-2006 10:23 PM
Re: Grepping pattern from a File
if you only find a single dbid in the file:
a=`grep dbid | awk -F'"' '{print $4}'`
Otherwise:
while read record
do
a=`echo $record | grep dbid | awk -F'"' '{print $4}'`
echo "This is your variable value" $a
done < input.dat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 07:43 PM
10-03-2006 07:43 PM
Re: Grepping pattern from a File
this retrun teh value in the variable dbid
dbid=$(awk -F"dbid=" '/dbid=/ {print $2}' file)
This command is indipendent by teh dbid position on the line. It founds line containg 'dbid=' and print the subsequent field. BY awk is not necessary to use cat and/or grep etc. awk is able to open a file.
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2006 05:57 PM
10-05-2006 05:57 PM