- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: stripping parenthesized data 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
04-19-2004 06:15 AM
04-19-2004 06:15 AM
I have created a script (with much help from the forum gurus...thank you) that manipulates a netlist file. The following line is used to strip out junk data included in parenthesis.
inputfilename=$1
cat $inputfilename | sed -e '/^#/D'| sed 's/(.*)//'
Problem is that some of my netnames, which are enclosed in single quotes, also include parenthesis.
'address(10)' for example
How can I still strip out the junk perenthesized data with out stripping out parenthsized data enclosed in single quotes? Your help in this matter is greatly appreciated.
Theresa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2004 06:56 AM
04-19-2004 06:56 AM
Re: stripping parenthesized data from a file
perl -ne 'next if /^#/;/\'([^\']*)\'/ && print $1,"\n"' <$inputfilename
This will skip lines beginning with "#" and any line in single quotes will have the contents of the quotes extracted and printed
Sounds like you probabily have more to it than this...
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2004 07:15 AM
04-19-2004 07:15 AM
Re: stripping parenthesized data from a file
NET '/8250_D(0)' U5-2 U4-3 U2-10
NET '/8250_D(1)' U1-9 U2-2 U3-3 U4-4 U5-5 (NET_TYPE, "critical")
NET '/CLK' U1-10 U2-10 ($G, $P)
There can be any number of connections, there may or may not be parenthesis in the signal name and there may or may not be a parenthesized statement at the end of the line. I could probably add a $_ to your print command to get the rest of the line, but that still does not get rid of the paranthesized junk at the end. Any other thoughts??
Theresa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2004 07:42 AM
04-19-2004 07:42 AM
Re: stripping parenthesized data from a file
perl -ne 'next if /^#/;/\'([^\']*)\'([^(]*)/ && print "$1 $2\n"' <$inputfilename
This adds the text after the second quote (') up to (but not including the next left parenthesis).
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:39 PM
04-20-2004 11:39 PM
Re: stripping parenthesized data from a file
Theresa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:44 PM
04-20-2004 11:44 PM
Re: stripping parenthesized data from a file
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2004 11:51 PM
04-20-2004 11:51 PM
Re: stripping parenthesized data from a file
I see now that it is a / followed by a \.
Theresa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 12:12 AM
04-21-2004 12:12 AM
Re: stripping parenthesized data from a file
I am getting a syntax error saying
'(' unexpected
I tried a couple of minor changes, but cannot get rid of it. Could you help??
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 12:43 AM
04-21-2004 12:43 AM
Re: stripping parenthesized data from a file
#!/usr/bin/perl
while (
if (!/^#/) {
/'([^']*)'([^\(]*)/ && print "$1---$2\n";
}
}
and execute as
./script < $inputfilename
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:21 AM
04-21-2004 01:21 AM
Re: stripping parenthesized data from a file
non-perl solution.
I assume you only have one pair of single quote.
I did not print the quote but this can be done easily.
sed -e '/^#/D'
do
A1=$(echo $line | cut -f1 -d\' )
A2=$(echo $line | cut -f2 -d\' )
A3=`echo $line | cut -f3 -d\' | sed 's/(.*)//'`
echo $A1 $A2 $A3
done
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 01:25 AM
04-21-2004 01:25 AM
Re: stripping parenthesized data from a file
this would be :
sed -e '/^#/D'
do
A1=$(echo $line | cut -f1,2 -d\' )
A3=`echo $line | cut -f3 -d\' | sed 's/(.*)//'`
echo $A1"'" $A3
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 03:39 AM
04-21-2004 03:39 AM
Re: stripping parenthesized data from a file
Perl Programming
Perl Cookbook
Sed & Awk
Mastering Regular Expressions
The perl one liners are only cryptic because the options passed to perl on the command line, assume certain code like while loops etc..
If you do alot of data manipulation programming you should find all the above books helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 04:01 AM
04-21-2004 04:01 AM
Solution--8<--- script
#!/opt/perl/bin/perl -n
/^#/ and next; # skip lines that start (^) with '#'
/ # start a match, this spans lines,
# because op the optional trailing 'x' flag. see later. it enables me to include comments
' # match a quote
( # start a capture to $1
[^']* # any character that is not a quote
# characters inside [] are a class/group.
# if it starts with a caret (^), the class is negated
# which means all character BUT the one's mentioned
# the star (*) means zero of more of the thing preceding the star
) # end of capture $1
' # a literal quote again
( # start of capture to $2
[^(]* # any number of non-open_paren
) # end of capture to $2
/x # end of match
and # if that matches
print "$1 $2\n"; # print the first capture followed by the second an a newline
-->8---
perl script <$inputfilename
Enjoy, Have FUN! H.Merijn [ who thinks that Rodney deserves 10 when you are going to assign points ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2004 06:00 AM
04-21-2004 06:00 AM
Re: stripping parenthesized data from a file
#!/bin/sh
inputfilename=$1
## First delete all lines starting with "#"
cat $inputfilename | sed -e '/^#/D'|
## Now print out on a seperate line each pin_number and its signal.
awk '{sig=$2;for (i=3; i<=NF; i++){printf("%s %s\n",$i, sig);}}' |
## Delete any line starting with parenthesis
sed -e '/#(/D' |
## Print out all lines with a character, a digit, a dash then a digit.
perl -ne '/^(\D+)(\d+)-(\d+)(.*)/ && printf"%-2s%6d%6d%6d %s",$1,$2,$3,$4,$_' >junk
## First delete all lines starting with "#"
cat $inputfilename | sed -e '/^#/D'|
## Now print out on a seperate line each pin_number and its signal.
awk '{sig=$2;for (i=3; i<=NF; i++){printf("%s %s\n",$i, sig);}}' |
## Delete any line starting with parenthesis
sed -e '/#(/D' |
## Print out all lines with a character, a digit, a dash, a character then a digit.
perl -ne '/^(\D+)(\d+)-(\D+)(\d+)(.*)/ && printf"%-2s%6d%6s%6d %s",$1,$2,$3,$4,$_' >>junk
cat junk | sort | cut -c22- # Sort the list and cut off at U number.
Now, I know I am duplicating some work here, but I could not figure out how to deal with letters after the "-" easily. It was easier to do the processing twice and does not seem to have slowed anything down...it works in seconds.
The perl suggestions from Rodney and Harry were still not working exactly as I needed and I would have had to add my other processing into the perl script format. Since I already have them working with sed and awk, it was easier to tackle it this way. I just ended up leaving the parenthesized junk data alone until after it was put on its own line with the awk command. Once on its own line, the entire line gets deleted if it starts with a "(". Works like a charm.
Just FYI, I did try Jean-Luc's method and it does work, but boy is it ever slow. It took over 5 minutes to process a nelist the took only seconds with the script above.
Thanks for the description of the perl synatax, Procura. It is helping me to understand perl a little better.