Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Best way to add 2 lines to multiple files
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Best way to add 2 lines to multiple files

Hi there.

Basically I have 50+.ovpn config files.

I need to add the following 2 lines UNDER the line persist-tun in each file.

remote-cert-tls server

auth-nocache

Doing it manually would be a pain.

Does anyone have any tricks to get this done in seconds?

Comments

  • theqkashtheqkash Member
    edited October 2016

    notepad++
    Search and Replace

    Take a look at search type - its "Extended"

    You can change it in each open file or in all files located in some directory on your hard drive.

    Thanked by 1xaitmi
  • @theqkash said:
    notepad++
    Search and Replace

    Take a look at search type - its "Extended"

    You can change it in each open file or in all files located in some directory on your hard drive.

    Thank you so much!

    I fired up one of my Windows VMs installed Notepad++ and got it done in 2 seconds. :)

  • eastoncheastonch Member
    edited October 2016

    ls | xargs -i echo "remote-cert-tls server \n auth-nocache" >> {}
    Maybe?

    Bascially, for each result in ls, (or dir) will be subject to:
    echo "remote-cert-tls server \n auth-nocache" >> filename.extension

    Note: This assumes that persist-tun is at the bottom, as this appends the above lines to the end of the file.

  • xaitmi said: Thank you so much!

    I fired up one of my Windows VMs installed Notepad++ and got it done in 2 seconds. :)

    No problem, you just owe me a beer ;-)

    Thanked by 1xaitmi
  • The more scriptable way is diff/patch. I just did this to update the encoding of a bunch of XML files:

    $ cat encoding.patch 
     1c1
     < <?xml version="1.0" encoding="iso-8859-1"?>
    ---
     > <?xml version="1.0" encoding="UTF-8"?>
     $ find . -name node.xml -exec patch {} encoding.patch  \;
    
Sign In or Register to comment.