sed replacement error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed replacement error
# 1  
Old 06-29-2015
sed replacement error

Hi

Code:
,"environment":"accent-release","build":"ac-1112_c_Alph_Nop-release_rele-1112_c_Alph_Nop-release_rele","tags":""


above is the config file, where in i want to replace value after build inside the double quotes... that value i'll be passing as parameter

for example if m passing

./a.sh abcd release, the o/p shul be


Code:
,"environment":"accent-release","build":"abcd release","tags":""

i tried below sed command, but to no avail

Code:
sed -e 's/"build":[[:alnum:]\{1,\}/"build":${parm}/g'

# 2  
Old 06-29-2015
Try this awk solution:
Code:
awk -F, '{for (i=1; i<=NF; i++) if ($i~/^"build":/) $i="\"build\":\"" PARM "\""}1' PARM="abcd release" OFS="," file
,"environment":"accent-release","build":"abcd release","tags":""

---------- Post updated at 16:35 ---------- Previous update was at 16:30 ----------

or a sed version (single quotes stop the shell from expanding variables):
Code:
sed -Ee "s/(\"build\":)[^,]*/\1${parm}/" file

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed replacement inplace

I need to make permanent changes in the file after find and replace using sed. for this i am using sed -i However this is not working. says sed: illegal option -- i I am working on Sun Solaris uname -a SunOS aspsun14 5.10 Generic_150400-13 sun4u sparc SUNW,SPARC-Enterprise any other work... (3 Replies)
Discussion started by: gotamp
3 Replies

2. Shell Programming and Scripting

SED replacement of placeholders

Hi All, I am facing a problem while using SED in Linux. I have a property file which contains a string local.mds.dir=${basedir}/deployCompositesIt has be to replaced with another string, and value of that string should be initialized at runtime. So I use placeholder there. My substituted... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

3. Shell Programming and Scripting

SED replacement

Hi, i have a file with lines, file.txt ------- test is fun testing is better I need to replace 'test' to 'develop' and i used, a=test b=develop sed "s,$a,$b,g" -------- but i see the word 'testing' is also replaced. Need some solution. Is there any way i could replace only 'test' ? (4 Replies)
Discussion started by: giri_luck
4 Replies

4. Shell Programming and Scripting

Replacement with sed

I am trying to replace the line which has string "tablespace" not case senstive.... with below simple script: mysrcipt.sh sed "s/.*/TABLESPACE USERS/g" create_table > tmp mv tmp create_table Is there any better way to do it? If Search string tooooooo long it will be tough to code in... (4 Replies)
Discussion started by: ganeshd
4 Replies

5. Shell Programming and Scripting

Help with sed replacement

This seems like it should be an easy problem, but I'm a noob and I can't figure it out. I'm trying to use sed, but would be happy to use anything that does the job. I am trying to trim off a fixed number of unknown characters from 2 different : delimited fields while keeping the intervening... (4 Replies)
Discussion started by: helix_w
4 Replies

6. Shell Programming and Scripting

String replacement using sed

I need to search and replace a particular string in a file. Only the exact match of the string should be replaced. eg: File contents : abc abcd abcdef --> Replace only 'abc' with 'xyz', but it should not replace abcd with xyzd. So the o/p should be: xyz abcd abcdef. How can this be done? I... (5 Replies)
Discussion started by: sngk
5 Replies

7. Shell Programming and Scripting

Need Replacement for sed

Hi Can anyone provide me the replacement of sed with xargs perl syntax for the below sed -e :a -e '/;$/!N;s/\n//; ta' -e 's/;$//' This should be without looping has to take minimal time for search (0 Replies)
Discussion started by: dbsurf
0 Replies

8. Shell Programming and Scripting

Replacement of sed with perl

Hi using the below cmd i am identifying wheether last character in each line in thousands of files as semicolon or not.If last character is semicolon i am removing semicolon .If last character is not semicolon then i am appending next line to present line . For example my input file consists of... (4 Replies)
Discussion started by: dbsurf
4 Replies

9. Shell Programming and Scripting

Complex sed replacement

Hi, I have a file that I would like to translate using sed. I can do some basic sed commands, but Im afraid this level is beyond me. I have this file - ...alter... .. ...65536... ... ...65536... ... ...alter... ... ...65536... etc What I would like to do is replace the first... (11 Replies)
Discussion started by: one_ring99
11 Replies

10. UNIX for Dummies Questions & Answers

Replacement using sed

Hi I have the following file that i need to run a sed command on 1<tab>running 2<tab>running 3<tab>running 4<tab>running I want to be able to replace a line i.e the second one with '2<tab>failed'. As the first number is unique that can be used to search for the relevant line (using ^2 i... (5 Replies)
Discussion started by: handak9
5 Replies
Login or Register to Ask a Question