Batch Remove Part Of Line In .txt

September 30, 2010 at 02:18:00
Specs: Windows 7, 2x2.8 4GB
Hi! I need help making batch file that will remove everything except two words.
So example.txt file looks like this (only 1 line is in file):

[00:03:34] He Has A 100.0 Pound Shark And Broke Record.

AND I need to get this:

100.0 Shark

in output.txt


how could i do this? I tryes with tokens but i failed. Need Help! Thanks! :))


See More: Batch Remove Part Of Line In .txt

Report •

#1
September 30, 2010 at 03:31:00
download gawk for windows then do this

this assumes you know the position of the words you want in the file.

C:\test>  gawk.exe "{print $5,$7}" file
100.0 Shark

while this assumes you don't know the positions but you know what you want to get.

C:\test> gawk.exe "{for(i=1;i<=NF;i++) if($i ~ /Shark/ || $i ~ /^[0-9.]+$/) {print $i} }" file
100.0
Shark

GNU win32 packages | Gawk


Report •

#2
September 30, 2010 at 03:49:38
thanks but is it possible that in your second example :

C:\test> gawk.exe "{for(i=1;i<=NF;i++) if($i ~ /Shark/ || $i ~ /^[0-9.]+$/) {print $i} }" file
100.0
Shark


are multiple words with unknow position. Like : shark, Dolphin, Blue Marlin
and that are, when found, printed in one line

100.0 Shark
45.8 Dolphin
87.2 Blue Marlin

???


Report •

#3
September 30, 2010 at 04:19:53
of course, just put the words you want in the regular expression

/Shark|Dolphin|Blue Martin/

GNU win32 packages | Gawk


Report •

Related Solutions

#4
October 1, 2010 at 14:00:32
thanks! :)

Report •

Ask Question