Email: bknpk@hotmail.com Phone: +972-54-7649119

 

ASIC/FPGA Design and Verification Out Source Services

sed to add a line to a file after a string match

A simple script to find a pattern in a file and than add a line to the file.

  1. When I needed to add a new button to all pages in this site, I used this script.
  2. The requirement is simple: per a given file, check if an input string is found in the file. If it does, add the new line after the line with the match.
  3. I do it on all files by the following command:
  4. find . -name "*.html" | xargs -n1 | xargs -i= ~/bin/add_html_button.unx =

  5. The script is shown below:
  6. #!/bin/bash

    sed '/match string/ a new string for new added line ' $1 > Tmp
    \mv -f Tmp $1


  7. Recently I saw that this can be done in one step:
    In this example I put perl line in remark by adding # at the beginning of the line.

  8. sed -i "s/^\(\&ads_0001;\)/#\1/" Home_2/udp_code.pl

  9. If any of the strings contains forward slash, one can use another character as the replace separator.
    sed -i "s,^\(\&ads_0001;\),#\1/," Home_2/udp_code.pl
    sed -i "s;OLD_SWITCH;$HTML_SWITCH;" Home_2/udp_code.pl




Please let me know what you think on my site.

 


Contact me now at:

  ...


I would be happy to offer my services. Call ASAP !


Home

Run a perl script from vim on a specified text block and convert verilog registers and wires to VHDL signals.






Search This Site


Feedback This Site




new pages on this site