I'm trying to search for "Primary Ins." string in tempfile. For every "Primary Ins." string that is found, a new line is inserted and put in number 1. Then, write out the newfile everything in tempfile + the number 1.
My testrun.bat file is follow:
@ECHO OFF
SETLOCAL
SET SED_PATH="C:\Program Files (x86)\GnuWin32\bin"
SET SED_PROGRAM=sed.exe
SET SED_PATH_PROGRAM=%SED_PATH%\%SED_PROGRAM%
sed -f C:\test\teststring.txt C:\test\tempfile.txt > C:\test\newfile.txt
Although a newfile.txt file is created, it's completely empty. Help please!
sed.exe can be found at C:\Program Files (x86)\GnuWin32\bin
This is where I defined on SED_PATH and SED_PROGRAM is calling sed.exe. Is this wrong? If so, how should I define it?
What I want to do is whenever "Primary Ins." is founded, a new line will be inserted along with a #1.
Thanks for all your help and looking into this.
---------- Post updated 12-06-11 at 12:00 PM ---------- Previous update was 12-05-11 at 06:10 PM ----------
I figured out the sed part. However, what I'm trying to do is to put in a 1 AFTER anyline that has 'Primary Ins.'
This code below gives me the opposite. It puts in a 1 BEFORE the line that 'Primary Ins.' is found. Help please!
Yes, SED_PATH is meaningless, the variable PATH that I mentioned is what you need to change. Or you could just try calling sed with the absolute path like I suggested.
CMD shell is annoying. You get no quoting at all, so every program handles quotes a different way. You DO get splitting. Every program decides what's really been split or not a different way. Best to put code into a file if you can, for the program to read unmangled.
If you can get or install awk, put this in a text file:
/^Primary Ins\./ { $0=$0 "\n" "1" } 1
Then do this:
awk -f ins.txt input.txt > output.txt
If it complains about 'unknown token', run dos2unix on ins.txt