- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Parse text in script
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
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-03-2001 05:42 AM
10-03-2001 05:42 AM
Example Log File
abcd aa abcd (xxxx)
What I want to return from this entry in the log using a script is
xxxx
I don't want the parenthesis. I have been trying to do this using an awk statement, but I seem to be leaving something out.
All help is appreciated
Thanks
Jeff
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 05:46 AM
10-03-2001 05:46 AM
Re: Parse text in script
Have you tried to use single quotes?
Rgds,
Pieter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 05:50 AM
10-03-2001 05:50 AM
Re: Parse text in script
Thanks for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:08 AM
10-03-2001 06:08 AM
Re: Parse text in script
This pipeline is one way to do it :
cat logfile | tr -d "()" | awk '{ print $4 }'
The "tr -d" deletes whatever characters are between the double quotes.
Regards,
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:10 AM
10-03-2001 06:10 AM
Re: Parse text in script
Create an awk script like this one (I've intentionally made it more verbose than necessary for clarity) called my.awk:
{
n1 = index($0,"(")
if (n1 > 0)
{
n2 = index($0,")")
if (n2 > n1)
{
s = substr($0,n1 + 1,n2 - n1 -1)
printf("%s\n",s)
}
}
}
cat yourfile | awk -f my.awk
That should do it, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:20 AM
10-03-2001 06:20 AM
Re: Parse text in script
You could do it with:
root:L1000>:awk '{print $3}' test | sed 's/)//g' | sed 's/(//g' > final
probably prettier ways to do it, but this would be quick....
RD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:21 AM
10-03-2001 06:21 AM
Re: Parse text in script
RD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:27 AM
10-03-2001 06:27 AM
Re: Parse text in script
Yet another variation in awk would be...
cat logfile | awk '{ sub(/\(/, ""); sub(/\)/, ""); print $4 }'
Enjoy,
Bruce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 06:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 07:24 AM
10-03-2001 07:24 AM
Re: Parse text in script
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 09:07 AM
10-03-2001 09:07 AM
Re: Parse text in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 09:27 AM
10-03-2001 09:27 AM
Re: Parse text in script
you'll probably have to add a NF>2 as in
'NF>2 {print $2;}'
this still doesn't in sure that there is a ( ) pair. i.e. two ) or two ( on a line will still generate output. For this situation I'd use the sed suggestion also because it matches a more "exact" pattern. i.e. a () pair. Although it will only output the pattern in the last () pair on a line if there is more then one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 11:20 PM
10-03-2001 11:20 PM
Re: Parse text in script
My reply was for processing a single line. For processing files, use:
sed -n 's/.*(\(.*\)).*/\1/p' file
to *only* display the bracketed contents within the file.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2001 08:01 AM
10-04-2001 08:01 AM
Re: Parse text in script
Example:
instead of logfile being
abcd aa abcd (xxxx)
what if
$1 from a NNM alert was
abcd aa abcd (xxxx)
Could I do something like this
Test=$1 | `awk '{print $4}'`
Where I want to set variable Test equal to xxxx
Thanks
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2001 08:22 AM
10-04-2001 08:22 AM
Re: Parse text in script
# X=`echo "abcd aa abcd (xxxx)"|awk '{print $4}'`
# echo $X
...would yield "(xxxx)"
Similarly, leveraging Robin's first solution:
# Y=`echo 'abcd aa abcd (xxxx)' | sed 's/.*(\(.*\)).*/\1/'`
# echo $Y
...would yield "xxxx"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2001 08:38 AM
10-04-2001 08:38 AM
Re: Parse text in script
Jeff