jftuga Posted September 8, 2006 Share Posted September 8, 2006 This command:mawk -F\t "$7 ~ /agin/ {print NR}" v.tsvhas this 3 line output:6824I want to run these three commands:mawk -f record.awk -v rec=6 v.tsvmawk -f record.awk -v rec=8 v.tsvmawk -f record.awk -v rec=24 v.tsvHow do I do this in a for loop? This is what I have tried:for /F "usebackq" %%R in (`mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv`) do mawk -f record.awk -v rec=%R v.tsvto debug, I am using:for /F "usebackq" %%R in (`mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv`) do @echo %Rwhich has the output of:RRRI have also tried this:for %%R in ('mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv') do @echo %Rwhich outputs:RRRRRRI have also tried single-quotes & back quotes to no avail and also fiddled around with the for command, but can not get this working.How can I make a for loop to run this command 3 times with # being replaced with 6, 8, and 24...mawk -f record.awk -v rec=# v.tsvI hope this makes sense,-John Link to comment Share on other sites More sharing options...
allen2 Posted September 8, 2006 Share Posted September 8, 2006 Perhaps this will work:for /f "delims=;" %%i in (`mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv`) do (mawk -f record.awk -v rec=%%i v.tsv) But i am pretty the following will work:mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv >%temp%\temptxt.txtfor /f "delims=;" %%i in (%temp%\temptxt.txt) do (mawk -f record.awk -v rec=%%i v.tsv) Link to comment Share on other sites More sharing options...
jftuga Posted September 8, 2006 Author Share Posted September 8, 2006 allen2,Thanks, I got it working with this:for /f "usebackq delims=;" %%i in (`mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv`) do mawk -f record.awk -v rec=%%i v.tsvIn this context what does delims=; do? I assume it tells the for loop that there are no delimiters? If this is the case, I still don't understand why this makes it work. Can you explain this?Thanks,-John Link to comment Share on other sites More sharing options...
allen2 Posted September 8, 2006 Share Posted September 8, 2006 The default delimiter is space so setting it to something that isn't in the lines will force %%i to take each entire line. Link to comment Share on other sites More sharing options...
jftuga Posted September 8, 2006 Author Share Posted September 8, 2006 Ahh, that makes sense. Thanks for all of your help. My batch file is running great now.-John Link to comment Share on other sites More sharing options...
jaclaz Posted September 9, 2006 Share Posted September 9, 2006 The default delimiter is space so setting it to something that isn't in the lines will force %%i to take each entire line.Interesting, but not really needed there are standard ways to do it:@echo offECHO Standard way onefor /F "tokens=*" %%A in ('dir *.cmd') do echo %%ApauseECHO Standard way twofor /F "delims=" %%A in ('dir *.cmd') do echo %%ApauseEcho allen2's wayfor /F "delims=;" %%A in ('dir *.cmd') do echo %%A@jftugaFor future use, you are getting the R's because the underlined part is wrong:for /F "usebackq" %%R in (`mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv`) do @echo %RThe variable is %%R, not %R:for /F "usebackq" %%R in (`mawk -F\t "$7 ~ /agin/ {print NR}" v.tsv`) do @echo %%Rjaclaz Link to comment Share on other sites More sharing options...
jftuga Posted September 10, 2006 Author Share Posted September 10, 2006 (edited) I thought I tried %%R as well and still got 'R's. Maybe I was doing something else wrong, too.Anyway, it is all working now. Thanks for your help.-John Edited September 10, 2006 by jftuga Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now