- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk or sed?
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
тАО11-22-2004 12:51 AM
тАО11-22-2004 12:51 AM
(one) (two) (three (test)) ((test1) five)
Each row has a variable number of fields.
Any ideas?
Regards,
Dave.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 01:01 AM
тАО11-22-2004 01:01 AM
Re: awk or sed?
Sounds like you can safely remove the leading open and trailing close parens.
Furthermore, you can remove any close-space-open combos.
Suggesting the following solution:
perl -pe 's/^\(//;s/\)$//;s/\) \(/ /g' file
Or if you do not need the space between open/close:
perl -pe 's/^\(|\)$|\) \(//g' x
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 01:02 AM
тАО11-22-2004 01:02 AM
Re: awk or sed?
sed could be used to prepare the data by strpping out all brackets.
sed s/(/ /g $varname
same thing for the close bracket.
Then a standard awk command
cat $var | awk `{print $1 $2 $3}`
So my answer with some tweaks is probably both.
cut command might be useful in replacing the awk command.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 01:10 AM
тАО11-22-2004 01:10 AM
Re: awk or sed?
(one \()(two)(\)three) ...
In that case Parse::RecDescent might help
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 01:12 AM
тАО11-22-2004 01:12 AM
Re: awk or sed?
Looks good. Execept I get a trailing ) after the four.
$ perl -pe 's/^\(//;s/\)$//;s/\) \(/ /g' test.txt
one two three (test) (test1) four)
Any ideas?
Regards,
Dave.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 01:21 AM
тАО11-22-2004 01:21 AM
SolutionThose are hard to 'see' in the itrc forums.
You'd have to append a few lines froma real file to analyze that.
If it is just optional trailing space(s) you can capture those with: \)\s*$
so:
perl -pe 's/^\(|\)\s*$|\) \(//g' x
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 02:17 AM
тАО11-22-2004 02:17 AM
Re: awk or sed?
# echo "(one) (two) (three (test)) ((test1) five)" | tr -d '()'
one two three test test1 five
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2004 02:19 AM
тАО11-22-2004 02:19 AM
Re: awk or sed?
using sed you can do this as,
# echo "(one) (two) (three (test)) ((test1) five)" | sed "s/(//g;s/)//g"
one two three test test1 five
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-23-2004 12:23 AM
тАО11-23-2004 12:23 AM
Re: awk or sed?
Regards,
Dave.