Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use sed to remove parenthesis. 1

Status
Not open for further replies.

motoslide

MIS
Oct 30, 2002
764
US
I searched this forum, but couldn't find in instance where this had been resolved. Sorry if i missed it.

Text file:
(1)
(1)
(2)
(3)
(4)
(6)
(14)

Desired output:
1
1
2
3
4
6
14

Sed Attempt:
sed '1,$ s/\(//g' '1,$ s/\(//g' <infile >outfile

First question: Can I link muliple search/replace together like that.
Second question: Do I need the "1,$" range with sed?
Third question: Why does it complain about an imbalance?

As always... Your help is my enlightenment.

Thanks

 
Code:
echo "
(1)
(1)
(2)
(3)
(4)
(6)
(14) " | sed 's/(//g;s/)//g'
You mask the parentheses if you like to define a capturing group, not if you mean parentheses themself.
Therefore the 'misbalanced'.
To use a list of multiple commands, I'm used to use a semicolon, not a comma.
I don't see the reason for using "1,$" - a range thing?
You don't need it, as far as I can see.

I used echo and not <infile>outfile to test it without generation of too much files.


seeking a job as java-programmer in Berlin:
 
Thanks much. I thought I had tried that first, then went on to make it harder.
Thank you for explaining the answer as well!
 
Another way:
tr -d '()' <infile >outfile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top