another sed question about parenthesis


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers another sed question about parenthesis
# 1  
Old 07-26-2005
another sed question about parenthesis

hi,

I'm trying to use sed to erase everything, up to, and including, the first closing parenthesis. for example:
input: blah blah blah (aldj) test (dafs) test test.
output: test (dafs) test test.

how would i do this?
I was fooling around with the parenthesis, and i only got it to apply to all parenthesis. This erased the 2nd closing parenthesis, which is not what i want. Here's what i had:
sed "s|*.)||" filename > output

thanks,
gammaman
# 2  
Old 07-26-2005
Code:
echo 'blah blah blah (aldj) test (dafs) test test.' | sed 's/^\([^)][^)]*\).*/\1)/'

# 3  
Old 07-26-2005
Alternative with out sed :

Code:
echo "blah blah blah (aldj) test (dafs) test test" | cut -d")" -f 2-

# 4  
Old 07-26-2005
Quote:
Originally Posted by vgersh99
Code:
echo 'blah blah blah (aldj) test (dafs) test test.' | sed 's/^\([^)][^)]*\).*/\1)/'

thanks for the post, but i'm trying to get so that only "test (dafs) test test" will be displayed and "blah blah blah (aldj)" will be cut off. The code works, but instead it cuts off "test (dafs) test test" and displays "blah blah blah (aldj)". How would I reverse this?

thanks,
Gammaman
# 5  
Old 07-27-2005
Quote:
Originally Posted by gammaman
thanks for the post, but i'm trying to get so that only "test (dafs) test test" will be displayed and "blah blah blah (aldj)" will be cut off. The code works, but instead it cuts off "test (dafs) test test" and displays "blah blah blah (aldj)". How would I reverse this?

thanks,
Gammaman
sorry for the confusion....
Code:
echo 'blah blah blah (aldj) test (dafs) test test.' |  sed 's/^[^)][^)]*) *\(.*\)/\1/'

# 6  
Old 07-27-2005
Quote:
Originally Posted by vgersh99
sorry for the confusion....
Code:
echo 'blah blah blah (aldj) test (dafs) test test.' |  sed 's/^[^)][^)]*) *\(.*\)/\1/'

thanks! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing spaces between parenthesis ()

Hello, i 've go a file with the following text: oracle@das (J005) 0 oracle@das (J008) 0 oracle@das (J050) 0 oracle@das (J038) ... (15 Replies)
Discussion started by: nms
15 Replies

2. Shell Programming and Scripting

How to get value from a close and open parenthesis?

Hi Gurus, I have an input like the one below. What i wanted to achieved is to create a select statement based from that information INPUTInsert into table_name (col1,col2,col3,col4,col5,DATE1,DATE2,col6,col7,col8,col9,col10,col11) values (6752,14932156,24,'ALL','Staff',to_date('04/17/2017... (6 Replies)
Discussion started by: ernesto
6 Replies

3. Shell Programming and Scripting

sed help adding parenthesis

I have the following data and want to put parenthis around the numbers: PARTITION PERIOD_MIN VALUES LESS THAN 10649 TABLESPACE ODS_DAILY_MF_AUM, PARTITION PERIOD_10649 VALUES LESS THAN 10650 TABLESPACE ODS_DAILY_MF_AUM, PARTITION PERIOD_10650 VALUES LESS THAN 10651 TABLESPACE... (2 Replies)
Discussion started by: BeefStu
2 Replies

4. Shell Programming and Scripting

Need help with Sed (replacing parenthesis and comma)

I have the following text as an input text: input.txt Results('Toilet', 'Sink', ) and i want to remove the last comma so the output is output.txt Results('Toilet', 'Sink' ) I tried using the following sed command, but I get a parsing error: sed s/, \)/\)/g input.txt >... (5 Replies)
Discussion started by: jl487
5 Replies

5. Shell Programming and Scripting

extract first argument in parenthesis

I have a file that, among other things, contains a tuple with words and the word count. I want to make a list of the words only. Ex: My file words.txt looks like: 0.1 sw-wn 9 - n: 97/903 p: 107/893neg: (film,771.1) | (movie,717.1) | (like,690.1) | (just,621.1) | (it's,607.1) | (time,543.1) |... (4 Replies)
Discussion started by: erinbot
4 Replies

6. Shell Programming and Scripting

Multiline parenthesis matching, with e.g. SED script, in LaTeX doc

In a LaTeX manuscript, I need to replace many occurrences of \emph{some string} with some string, i.e. whatever string is inside. The string inside often may extend over several lines, and there may be other occurences of curly brackets inside it. So for example \emph{this \it{is} a... (5 Replies)
Discussion started by: sune
5 Replies

7. Shell Programming and Scripting

use of parenthesis() in shell programming

What's the use of parenthesis () in shell programming ? I saw this in one of the posts in this forum : echo $($1) What confounded me was that it evaluated the inner expression and then the outer one, almost like eval. It seemed like it did this in passes. (2 Replies)
Discussion started by: daudiam
2 Replies

8. UNIX for Dummies Questions & Answers

Problem in extracting the string between parenthesis

Hi Team, I am not able to extract string between parenthesis.I need to extract string between first parenthesis only. Please find the sample data and code. But the below my code is returning "DW_EFD_TXN_ID", "PRCS_DTE" & INITIAL 52428800 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645... (12 Replies)
Discussion started by: suriyavignesh
12 Replies

9. Shell Programming and Scripting

Cleanup between parenthesis

Hi, I am trying to clean up data between parenthesis () in a file. See example below.... Input File : (New York) Chicago (London) New York (Chicago) London New York Chicago (London) (New York) (Chicago) (London) New York (Chicago) ... (3 Replies)
Discussion started by: msalam65
3 Replies

10. Programming

how to check parenthesis in MSVC++

how do i turn on the option to check for opening and closing parenthesis in Microsoft VC++? I remember there is a setting somewhere in the options in the MS VC++ environment but not sure.. thanks (4 Replies)
Discussion started by: npatwardhan
4 Replies
Login or Register to Ask a Question