I want an batch scripting equivalent to this AWK script:
awk '{print $3}'
A file has this content:
XXX YYY : 8
Rrr rrr : 7
ddd rrr : 9
I want to get a batch script to print
8, 7, 9
Is there any way by which each value can be assigned to a loop and redirected to if condition?
I can't tell if your asking for a Windows Batch script or an awk script, so here's both:
test.txt:
XXX YYY : 8
Rrr rrr : 7
ddd rrr : 9
AWK:
awk 'NR > 1 {printf ", "}{printf $4}END{printf "\n"}' test.txt
Output:
8, 7, 9
Windows Batch script:
@echo off
SET _c=
FOR /F "tokens=4 delims= " %%G IN (test.txt) DO (
IF DEFINED _c <nul set /p z=", "
<nul set /p z=%%G
SET _c=1
)
Output:
8, 7, 9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With