Batch File to Extract data

May 1, 2009 at 03:33:18
Specs: Windows XP
Batch file which can extract lines in between to two specific words.

See More: Batch File to Extract data

Report •


#1
May 1, 2009 at 03:49:16
More detail may help. Multiple threads probably won't.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
May 1, 2009 at 09:42:36
Hi M2,

Basically we have flat file records as follows,

01#77735601#gggg#XXXXXTTTTT
03#74335941#ttgg#XXXXXJJTTT
01#77665601#ggll#XXXXXTTUUT

Based on the first 2 characters, we need to seperate the records.

For example, records beginning with 01# should be written in a seperate file and for 02#, 03#....06# like wise.

Is it possible in .bat script? we tried with FINDSTR command but it seprates all the occurances.

Plz advice.


Report •

#3
May 2, 2009 at 00:24:23
:: get lines xx# into sep files

@echo off & setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in (myfile) do (
set str=%%a
set str=!str:~0,3!
echo %%a>> !str!
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
May 2, 2009 at 01:49:32
if you can install and use gawk for windows (see my sig), just one line.
C:\test>gawk -F"#" "{print $0 > $1\".txt\"}" file.txt
C:\test>more file.txt
01#77735601#gggg#XXXXXTTTTT
03#74335941#ttgg#XXXXXJJTTT
01#77665601#ggll#XXXXXTTUUT
02#77735601#gggg#XXXXXTTTTT
03#74335941#ttgg#XXXXXJJTTT
04#77665601#ggll#XXXXXTTUUT

C:\test>more 01.txt
01#77735601#gggg#XXXXXTTTTT
01#77665601#ggll#XXXXXTTUUT

C:\test>more 02.txt
02#77735601#gggg#XXXXXTTTTT

C:\test>more 03.txt
03#74335941#ttgg#XXXXXJJTTT
03#74335941#ttgg#XXXXXJJTTT

C:\test>more 04.txt
04#77665601#ggll#XXXXXTTUUT

Unix Win32 tools | Gawk for Windows


Report •


Ask Question