Batch to Append Chars and Remove Lines

Microsoft Windows xp professional sp2c e...
July 13, 2010 at 16:37:10
Specs: Windows 2003 or 2008, Intel/4GB
Hi All,

I would like to have a windows batch script which can run on XP and NT machines and can perform...

Requirements:

1. Batch program should modify the file placed in D:/Test/ folder.
2. First and Second lines with 0000 are Header and Trailer. Batch script should prefix H before 1st 0000 and T before second 0000.

3. Script should remove all lines other than which has value 5000 in 1st column and 0 in 5th column.


File Snippet Before Execution of Script:

0000 00000 00000008499 0000999 0
0000 00000 00000008499 0000999 0
1000 00000 00000008499 0000999 0
9999 00000 00000008499 0000999 0
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 7
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 7
4300 09999 00000008499 0000999 0
6000 09999 00000008499 0000999 0
1000 09999 00000008499 0000999 7

File Snippet After Execution of Script:-

H0000 00000 00000008499 0000999 0
T0000 00000 00000008499 0000999 0
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 0

Thanks,
Phani Akella


See More: Batch to Append Chars and Remove Lines

Report •

#1
July 13, 2010 at 16:58:57
here's a one liner for you
C:\test>sed -n "1 s/^/H/p;2 s/^/T/p;/^5000.*0$/p" file
H0000 00000 00000008499 0000999 0
T0000 00000 00000008499 0000999 0
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 0
5000 09999 00000008499 0000999 0

you can download sed here

GNU win32 packages | Gawk|sed


Report •

#2
July 14, 2010 at 18:31:47
Hi,

My file is Tab delimited. And first 2 lines Header are Trailer are of 14 fields and where as Transaction records (are around 56 fields). Sed command has to remove all lines other that which has value 5000 in 1st column and 0 in the 5th column.

Instead of a command. Can i make this into a batch file and perform all the changes on a click on the batch with out changing the file name?

Thanks,
Phani Akella


Report •
Related Solutions


Ask Question