Computing.Net > Forums > Programming > Cut few text in a matched line

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Cut few text in a matched line

Reply to Message Icon

Name: Kalai
Date: April 13, 2009 at 00:56:49 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi, i'm having a log file wherein i need to pick up only few values/text from the matched string lines and put into another file. I'm 50% done with that. i used "FIND" command to find the matched string lines & also used ">" command to put into another file.
like FIND /I "str" log.txt > newfile.txt

The output of this command is picking up the entire line of the matched string from the log file & put into another file.

BUT,
My requirement is : need to copy only few text in the matched line & placed it into another file.
Let say for eg: log.txt contains

map1 records read: 100
map1 records written: 200
map1 records error: 0
map2 records read: 1234
map2 records written: 123
map2 records error: 2
.
.
.

From this log file, i need to go for search based on map name (map1,map2 etc..) and want pick up only the count of records read, written ,Error values into another file. ONLY the count values.

If i take up map1 as string then i need to put only 100,200, 0 into new file.
In unix, i know the solun, we can go for grep & cut command but i dont know how it can be done via windows batch process.

can anyone help me whats the command to CUT some text in a line using batch process?



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: April 13, 2009 at 04:48:27 Pacific
Reply:

with batch you can use tokens and delim with the for loop. else, you can use vbscript. read the file line by line and do a split on each line. Use Instr to check if your word in in the line.
Last but not least, if you can download unix tools for windows(see my sig), you can use the regular grep/cut as well.

Unix Win32 tools | Gawk for Windows


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Cut few text in a matched line

Scripts to search for a text in a view source www.computing.net/answers/programming/scripts-to-search-for-a-text-in-a-view-source/19961.html

Print multipl lines in a cell in VB www.computing.net/answers/programming/print-multipl-lines-in-a-cell-in-vb/4945.html

Sed:Add text to end of line in file www.computing.net/answers/programming/sedadd-text-to-end-of-line-in-file/15109.html