Solved I am not familiar with command prompts and commands pls help

May 16, 2012 at 03:32:56
Specs: Windows 7
Hi
HH01|F|20120501
A|100392595|170|LASA|190147||01||||3663|4|2012-05-01 17:47:11
A|128568117|170|LASA|30609||01||||3692|2|2012-05-01 17:47:11
A|101395229|170|LASA|F9593||01|2|7810|1.00051216|3905|2|2012-05-01 17:47:11
A|102303360|170|LASA|G2537||01|2|10534|1.00037972|5267|2|2012-05-01 17:47:11
A|101311984|170|LASA|H7433||01|2|7688|1|3844|1|2012-05-01 17:47:11
A|102316518|170|LASA|H7546||01|1.66666666|5|2.66666666|3|1|2012-05-01 17:47:11
A|103314063|170|LASA|I4579||01|2|2|3|1|1|2012-05-01 17:47:11
A|125535160|170|LAB1|B2975||01||||1|1|2012-05-01 17:47:11
TT01|8

the above data is present as a single file in txt
I need to split this data such tht Header(HH....), data(A| .....8 lines) and trailer (TT..) records comes in diffrent txt files. Please help me ...............!! to execute it in MS dos .....


See More: I am not familiar with command prompts and commands pls help

Report •


#1
May 16, 2012 at 12:18:07
✔ Best Answer
findstr "HH" testtext.txt > header.txt
findstr "A" testtext.txt > body.txt
findstr "T" testtext.txt > trailer.txt

::this will search and create a new file based on the above input file, assuming its
::named testtext.txt, and then out put header, body and trailer.

mike


Report •

#2
May 16, 2012 at 14:58:24
You say MS-DOS, but your specs say Windows 7. Which OS are you talking about?

How To Ask Questions The Smart Way


Report •

#3
May 17, 2012 at 05:14:54
Hi mikelinus
Thanks a lot!!
I want to clear another doubt wht if the above body of the txt has lines starting with different letters such as A-Z..unlike 'A' in the above.......i would like to know whether findstr would work or if not is there any other option....
and wt would be tht option...


!!@


Report •

Related Solutions

#4
May 17, 2012 at 06:38:49
The code above works for the file you posted, if there are variations, it would not work the same.

all the above code looks for is if the line has HH,A, and T. I did it this way because of how you claimed the data file would be laid out.

mike


Report •

#5
May 19, 2012 at 04:51:00
To throw my two cents in, I would add the /b switch to look for the search strings only at the beginning of the line:

findstr /b "HH" testtext.txt > header.txt
findstr /b "A" testtext.txt > body.txt
findstr /b "T" testtext.txt > trailer.txt

Untested, relating to second question:

findstr /r "^[^HAT]" testtext.txt > investigate.txt

In theory, the above would use regular expressions (/r) to search at the beginning of the line (first ^) for any character not (second ^) in the class (everything between [ and ]) "HAT".

The following which adds the wild card: "." and repeat: "*" may be more appropriate:

findstr /r "^[^HAT].*" testtext.txt > investigate.txt

When your only tool is a hammer, every problem looks like a nail.


Report •

Ask Question