sed Command to replace particular value.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed Command to replace particular value.
# 8  
Old 04-29-2017
awk suggestion:

Code:
awk -v fields=8,10,16,17,22 -F' *= *|[ \t]*' '
  BEGIN {
    split(fields,F,/,/)
    for(i in F)
      C[F[i]]
  }

  {
    for(i=1; i<NF; i++)
      if(!(i in C))
        $(i+1)=0
    sub(/ /,"=")
    print
  }
' file


Last edited by Scrutinizer; 04-29-2017 at 11:52 AM..
# 9  
Old 04-29-2017
Another way in (gnu) sed:
Code:
echo "8,10,16,17,22" | sed 's/,/;/g;s/[0-9]\+/s\/[0-9]\\+\/A\&A\/&/g' | sed -f - -e 's/^\|$/ /g;:B;s/\([^A]\)[0-9]\+\([^A]\)/\1A0A\2/;tB;s/A//g;s/^ \| $//g' file

Regards.
# 10  
Old 05-02-2017
thank you all..

Last edited by Preeti Chandra; 05-03-2017 at 08:00 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed replace command

Hi. I need to append/prefix an & character to every 'single' & character (not when there are 2 or more grouped together) I find in a file. I can do it using this cmd: cat ${file} | sed -e 's/&/&&/g' > ${new_file} How can I modify this to ensure I only replace single &'s and not operate... (11 Replies)
Discussion started by: user052009
11 Replies

2. Shell Programming and Scripting

Need to log the sed command used to replace

In a shell script I am replacing the asterisks in a file: sed "s/\*/"0"/g" /home/download/$COMPANY_CODE/file_new > /home/download/$COMPANY_CODE/fileI need to log which positions were replaced & position(01:20) from the line it was replaced in. I am not sure how to do so. Also, instead of... (11 Replies)
Discussion started by: tomj5141
11 Replies

3. Shell Programming and Scripting

Find and replace using sed command

The content of the file filea.txt is as follows. --------- case $HOSTNAME in aaa) DS_PARM_VALUE_SET=vsDev APT_Configuration_File=/appl/infoserver/Server/Configurations/2node.apt ;; bbb) DS_PARM_VALUE_SET=vsQA... (3 Replies)
Discussion started by: kmanivan82
3 Replies

4. Shell Programming and Scripting

sed command to find and replace

Hello All, I need a sed command to find and replace below text in multiple files in a directory. Original Text :- "$SCRIPT_PATH/files" Replace with :- "$RESOURCE_FILE" Thank you in advance !!! Regards, Anand Shah (1 Reply)
Discussion started by: anand.shah
1 Replies

5. Shell Programming and Scripting

sed command to replace a word with new line and /

Hi, I have been trying to replace the key word "SQL> spool off " with "/ show errors" with out double quotes in all the files in a directory. above show erros should be displayed next line Could you please help me how to do that. I have tried something like this... (3 Replies)
Discussion started by: pointers
3 Replies

6. Shell Programming and Scripting

search and replace with sed command

hi, suggest me in the below script.. if In above I wanna replace "" with "]". (2 Replies)
Discussion started by: divya bandipotu
2 Replies

7. Shell Programming and Scripting

sed command to replace a character at last

Hi All, I have a file having one line only. It is like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|78|0037| I want to replace the numbers in last two columns by As. It should look like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|AA|AAAA| Please, suggest me any shell... (12 Replies)
Discussion started by: mukeshbaranwal
12 Replies

8. Shell Programming and Scripting

Replace with a variable in sed command

Hello, I have this command and it works fine. My question is that how can we replace the N by a variable, to print for instance a big number of lines. It means if I want 100 lines after an expression, to not put "N" 100 times in the sed. Code: $ sed -n '/aaa/{n;N;N;s///g;s/;/; /g;p;}'... (2 Replies)
Discussion started by: rany1
2 Replies

9. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

10. Shell Programming and Scripting

sed search and replace command

Hi, I would like to seek help on how i can arrive on this result. sample.txt: product_code IN (param001) and product_type IN (param004) product_code IN (param002) and product_type IN (param005) product_code IN (param003) and product_type IN (param006) I would like to change the param001... (1 Reply)
Discussion started by: janzper
1 Replies
Login or Register to Ask a Question