Problem with sed string substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with sed string substitution
# 1  
Old 11-04-2008
Problem with sed string substitution

Hi,

heres my problem:


echo "aaaa(aaaa(aaa" | sed 's/a.*(//g'

gives aaa

but it should give aaaa(aaa


.*( should find any string to the appearance of (, but it finds any string to the last appearance, any idea why, and how to do this?

and what if the string ist
aaaa(aaaa(aaaa(aaa and i want to replace it to the second appearance


this is just a small example, but I hope it's clear what I mean


cheers

funksen
# 2  
Old 11-04-2008
I am not sure if I understood what you want, but maybe this is can help:
Code:
echo "aaaa(aaaa(aaa" | sed 's/a[^(]*(//1'
aaaa(aaa

# 3  
Old 11-04-2008
thanks alot, that is exactly what I'm looking for

the clue ist [^(]*
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - String substitution within specified section in ini type file

Hello. I am trying to modify a config file which is in windows *.ini type file. I have found a piece of code here :linux - Edit file in unix using SED - Stack Overflow As I can't make it doing the job , I am trying to find a solution step by step. here a modified sample file : my_sample.ini... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Problem with substitution in sed??

Hi alll I have a file with this content ale,AAM,id2_1_2_1_1,23,2013-01-30,1,1 ale,BAND,id2_1_1_1_1,31,2013-01-28,1,1 ale,CAI,id2_1_1_1_1,23,2013-01-28,1,1 ale,CAI,id2_1_1_1_4,23,2013-01-28,1,1 ale,CAI,id2_1_2_1_1,23,2013-01-30,2,1 ale,NAST,id2_1_1_1_1,23,2013-01-29,1,1... (1 Reply)
Discussion started by: nikhil jain
1 Replies

3. Shell Programming and Scripting

sed substitution problem

I'm writing my first script and I have all the other commands I'm using working properly, but I'm having one final issue with a sed. I've looked on the forums for some answers, which have been close but sed is quite confusing to me. My problem is that I have a file called CylinderAtom1.txt... (3 Replies)
Discussion started by: 1Aegis1
3 Replies

4. Shell Programming and Scripting

sed variable substitution problem

Hi, I am facing a strange problem. I have a script that used the following to search and replace text: sed 's/'"${find_var_parm}"'/'"${find_var_filter}"'/g' $ParmFile > $TempFile The values of $find_var_parm and $find_var_filter are set based on search criteria. The above seems to be working... (2 Replies)
Discussion started by: arsh
2 Replies

5. Shell Programming and Scripting

problem with sed while replacing a string with another

Hi, I have a line something like this sys,systematic,system I want to replace only the word system with HI I used sed for this as below echo sys,systematic,system | sed 's/system/HI/' but I got output as sys,HIatic,system I wanted output as sys,systematic,HI Please tell me... (9 Replies)
Discussion started by: friendyboy
9 Replies

6. Shell Programming and Scripting

sed substitution problem

Can anyone please help me on this. i have a file with lines say X X3200 X X X X2400 X X4100 I want to use sed to put the numbers in braces. the output should be like, X X(3200) X X X X(2400) X X(4100) (7 Replies)
Discussion started by: diliphp
7 Replies

7. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies

8. Shell Programming and Scripting

Sed - substitution for whole string

Hello I have several files where a string similar to this appears: /home/workload/bin/ProcDly/scrpts/T54.sh > $LOG I need to change it to something like this: $VARIABLE > $LOG However, due to the configuration of the rest of the files, I should only find this string by the... (4 Replies)
Discussion started by: Scarlos
4 Replies

9. UNIX for Dummies Questions & Answers

sed/awk String problem

I would appreciate it if any one can guide me in using awk perhaps sed in extracting some values from a long string. here is an example. .......some lines here........ ........ aaaa bbbb cccc ddddd eeeee fffff gggg (time:hhhh)........ ......some lines here also.......... How can I extract... (2 Replies)
Discussion started by: odogbolu98
2 Replies

10. UNIX for Dummies Questions & Answers

Sed String Substitution

Hi! I've the following script code with an input parameter: sed 's/oldstring/$1/g' myfile > newfile (I launch it with comman line: $ MyShell newstring) Problem: the substituion doesn't work (oldstring becomes $1, instead of newstring). How could I solve this situation? Thanks, ... (2 Replies)
Discussion started by: pciatto
2 Replies
Login or Register to Ask a Question