Jump to content

Help with batch file to read (certain) lines in a file


Recommended Posts

Hi everyone,

I have a script that I have written in *nix that works fine. Basically, it searches through a text file and finds expired entries. The only problem is that each entry is on multiple lines. For example:

Title:  Expired

User: John Doe
email: [email protected]
----------------------

Title: Something

User: Jane Doe
email: [email protected]

I would like to write a similar .bat file to run in Windows. If we can get it to do the following them I can tweak it further:

- Open the input file (let's just call it in.txt)

- Search for all lines that contain "Expired"

- If an expired entry is found, then echo the username and email that are 2 and 3 lines later.

I have a BASH script that does this on *nix machines, and when I tried to copy it to Windows and run it with Cygwin, I couldn't get it to work; it keeps giving me an error stating that the "done" token of my while loop is unexpected (which it shouldn't be). I don't want to have to install Cygwin on a bunch of machines just to get this script to work so I was just trying to copy ONLY the cygwin DLL files that I needed. It finally stopped complaining about missing DLL files but it still doesn't work.

Similarly, I could accomplish this task with a Java program, but I don't want to have to install Java on a bunch of a machines either. It seems like a .bat file would be best since it doesn't require any extra installations. Hopefully the above description is clear. Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy