Problem with substitution in sed??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with substitution in sed??
# 1  
Old 02-15-2013
Problem with substitution in sed??

Hi alll


I have a file with this content

Code:
Code:
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
ale,NAST,id2_1_1_1_1,31,2013-01-29,1,1
ale,NST,id2_1_2_1_1,31,2013-01-28,1,1
ale,PAB,id2_1_1_1_1,31,2013-01-30,2,2
ale,PAB,id2_1_2_2_3,23,2013-01-28,1,1

when I'm using this command

Code:
Code:
sed "/id2_1_*/id2_1_\*/g"


It is not replacing all the occurences of id2_1_1 to id2_1_*

required o/p is
Code:
Code:
ale,AAM,id2_1_*,23,2013-01-30,1,1
ale,BIAND,id2_1_*,31,2013-01-28,1,1
ale,CAI,id2_1_*,23,2013-01-28,1,1
ale,CNAI,id2_1_*,23,2013-01-28,1,1
ale,CAI,id2_1_*,23,2013-01-30,2,1
ale,NAST,id2_1_*,23,2013-01-29,1,1
ale,NAST,id2_1_*,31,2013-01-29,1,1
ale,NAST,id2_1_*,31,2013-01-28,1,1
ale,PAB,id2_1_*,31,2013-01-30,2,2
ale,PAB,id2_1_*,23,2013-01-28,1,1

s
# 2  
Old 02-15-2013
Try:
Code:
sed 's/id2_1_[^,]*/id2_1_*/' file

Add the g flag if multiple strings may be matched by the pattern on a line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Substitution with sed

I have a file with some numbers having single quotes around them which I want to remove. i.e. '923930' -> 23930 If it can be done without using sed thats fine. I have tried with sed but can't think how to replace this pattern on only the numbers (13 Replies)
Discussion started by: user_invalid
13 Replies

3. UNIX for Dummies Questions & Answers

Help with sed substitution

I'm a noob to unix, and I have a line of data like the following: title=Boston|tcolor=green|desc=Large city in New England|url=www.boston.com Is there a way to change a field value with sed substitution? (i.e. change tcolor=green to tcolor=blue) I figured out: sed... (19 Replies)
Discussion started by: stabby
19 Replies

4. Shell Programming and Scripting

sed substitution

Using sed I'm trying to replace 'string' with ']' while retaining case and ignoring words with 'string' in it along with additional characters like 'strings' and those which already contain the ] wrapper. I'm hoping to do it with sed and the right expression, if possible. Example: Apple... (2 Replies)
Discussion started by: tom.lee
2 Replies

5. 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

6. Shell Programming and Scripting

sed substitution

Hi I am trying to do a text insertion in a text file at a particular line number in a shell script. However its not working. sed '122i\ > for j in \`echo $MyList\` ; do perl -pi -e\'s#01\/01\/2009#01\/01\/2011#\' $j ; done' $HOME/MyScript.ksh The Actual line to be inserted at line 122... (5 Replies)
Discussion started by: som.nitk
5 Replies

7. 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

8. Shell Programming and Scripting

Help with sed/substitution!

I have file.txt 1 4 7 9 3 I want to replace the tabs with a space, but my code doesn't work. cat file.txt | sed 's/"\t"/ /g' > t.txt But file is still the same. Numbers seperated by tabs instead of spaces. Help? (2 Replies)
Discussion started by: Bandit390
2 Replies

9. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: funksen
2 Replies

10. UNIX for Dummies Questions & Answers

Substitution using sed

I know we can substitute a string using sed but how? For example: sed 's/(old variable)/(new variable)/ details.dat Am I suppose to put $old variable or whatever? Because I tried many times, it didnt work by putting $old variable. Am I suppose to enclose it with "" or ''? Please help (3 Replies)
Discussion started by: Ohji
3 Replies
Login or Register to Ask a Question