Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.comp.os.windows-10 > #164866

How to insert contents of a file (or a line of text) at a given location inside hundreds of text files?

From Andy Burnelli <spam@nospam.com>
Newsgroups alt.comp.os.windows-10, alt.comp.microsoft.windows, alt.msdos.batch
Subject How to insert contents of a file (or a line of text) at a given location inside hundreds of text files?
Date 2022-12-19 07:43 +0000
Organization Aioe.org NNTP Server
Message-ID <tnp4n3$jrm$1@gioia.aioe.org> (permalink)

Cross-posted to 3 groups.

Show all headers | View raw


How can one most easily insert contents of a file (or a line of text)
at a given line-number location inside each of hundreds of text files?

It seems that vpngate.net vpn configuration files now require a username
(of vpn) and a password (of vpn), which isn't a big deal for most people
who don't use automation, as they'd just type the login/password in when
asked by their openvpn client graphical user interface.

But I change the Time Zone & VPN server every few minutes via batch files.

It's easy to _manually (aurgh!) add at line 103 the "password.txt" line, 
but what might you think is an easy way to add that line to _every_ file?

Here's what I do manually (which, admittedly, is a PITA albeit simple):

 1. cd directory-containing-hundreds-of-openvpn-config-files
 2. vim *.ovpn
 3. :103
 4. ~r include.txt
 5. :write (abbreviated as :w)
 6. :next  (abbreviated as :n)

 1. That manual process starts in a directory of many files
 2. and then edits, one by one, each of a few hundred *.ovpn files;
 3. and then it jumps to line 103 (it's always in the same spot); 
 4. and then I include the file, which contains the following line only:
    auth-user-pass C:\\path\\config\\passwd.txt
 5. and then I write the *.ovpn file;
 6. and then I skip to the next *.ovpn file.

Where the contents of the c:\path\config\passwd.txt file is two lines:
    vpn
    vpn 
The first being the username & the latter being the password as described
in the <http://vpngate.net> home page (this is a brand new requirement).

If I were to simply append the line to the _end_ of the *.ovpn files, 
instead of inserting thatline at line 103, I could use a Windows command
line foreach loop to append the "include.txt" file to the *.ovpn file:
 for %f in (*.ovpn) do type include.txt >> %f
But how can I _insert+ that one-line include.txt file at line 103?

How can one most easily insert contents of a file (or a line of text)
at a given line-number location inside each of hundreds of text files?

Back to alt.comp.os.windows-10 | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Andy Burnelli <spam@nospam.com> - 2022-12-19 07:43 +0000
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Jeff Barnett <jbb@notatt.com> - 2022-12-19 00:53 -0700
    Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Paul <nospam@needed.invalid> - 2022-12-19 05:32 -0500
      Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Andy Burnelli <spam@nospam.com> - 2022-12-19 16:36 +0000
        Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Paul <nospam@needed.invalid> - 2022-12-19 12:53 -0500
      Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Herbert Kleebauer <klee@unibwm.de> - 2022-12-20 19:15 +0100
    Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Chris <ithinkiam@gmail.com> - 2022-12-20 11:23 +0000
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Andy Burns <usenet@andyburns.uk> - 2022-12-19 09:48 +0000
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? "Kerr-Mudd, John" <admin@127.0.0.1> - 2022-12-19 09:50 +0000
    Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Big Al <Bears@invalid.com> - 2022-12-19 10:42 -0500
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? Herbert Kleebauer <klee@unibwm.de> - 2022-12-19 22:51 +0100
  Re: How to insert contents of a file (or a line of text) at a given location inside hundreds of text files? "R.Wieser" <address@not.available> - 2022-12-20 09:16 +0100

csiph-web