batch file to print tokens of different lines
Posted: 30 May 2011 05:53
Hi All
Can you please help me solve this issue:
I have a text file as follows (between the lines ------):
-------------------------------text file contents below--------------------
some code and code2 other
29 4 14 ddd 208 16/3 R2C
PRODNAM MANDATE SERNO MASTRP
neededx 11W04 TD3A057135 951
SLSTATE DATE TIME
0 110415 031735
some code and code2 other
29 4 13 ddd 208 16/3 R2C
PRODNAM MANDATE SERNO MASTRP
neededy 11W04 TD3A057068 951
SLSTATE DATE TIME
0 110415 031624
some code and code2 other
29 5 10 2/ddd 208 459/1 R4B
PRODNAM MANDATE SERNO MASTRP
neededz 11W05 TD3A076719 936
SLSTATE DATE TIME
0 110415 030400
some code and code2 other
29 4 14 ddd 208 16/3 R2C
PRODNAM MANDATE SERNO MASTRP
neededv 11W04 TD3A057135 951
SLSTATE DATE TIME
0 110415 031735
-------------------------------text file contents above--------------------
Note that the text file appears as repeated blocks and the heading of each block is the same.
i want to output the following :
- print the heading once
-under the heading :print the first 3 tokens from the second line, and the fourth token from the the fourth line of the block.
example(output required from obove file):
===============================
some code and code2 other
29 4 14 neededx
29 4 13 neededy
29 5 10 neededz
29 4 14 neededv
My trial to solve it:
=================
regarding the heading, since it is well known i can delete it and write it once, that's OK, then i deleted the lines that are not necessary (including heading) as follows:
type filename.txt | FIND/v "PRODNA" | FIND/v "SLSTAT" | FIND/v "some" >>file2.txt
so ,now i have the file as follows:
29 4 14 ddd 208 16/3 R2C
neededx
29 4 13 ddd 208 16/3 R2C
neededy
29 5 10 2/ddd 208 459/1 R4B
neededz
29 4 14 ddd 208 16/3 R2C
neededv
the remaining is the get the fourth token from the second line not the first one, this lead to thinking about coding based on the line number (odd,even) .....but i have no more success.
your help is appreciated ,regardless if built on my trial or not.
Regards
Can you please help me solve this issue:
I have a text file as follows (between the lines ------):
-------------------------------text file contents below--------------------
some code and code2 other
29 4 14 ddd 208 16/3 R2C
PRODNAM MANDATE SERNO MASTRP
neededx 11W04 TD3A057135 951
SLSTATE DATE TIME
0 110415 031735
some code and code2 other
29 4 13 ddd 208 16/3 R2C
PRODNAM MANDATE SERNO MASTRP
neededy 11W04 TD3A057068 951
SLSTATE DATE TIME
0 110415 031624
some code and code2 other
29 5 10 2/ddd 208 459/1 R4B
PRODNAM MANDATE SERNO MASTRP
neededz 11W05 TD3A076719 936
SLSTATE DATE TIME
0 110415 030400
some code and code2 other
29 4 14 ddd 208 16/3 R2C
PRODNAM MANDATE SERNO MASTRP
neededv 11W04 TD3A057135 951
SLSTATE DATE TIME
0 110415 031735
-------------------------------text file contents above--------------------
Note that the text file appears as repeated blocks and the heading of each block is the same.
i want to output the following :
- print the heading once
-under the heading :print the first 3 tokens from the second line, and the fourth token from the the fourth line of the block.
example(output required from obove file):
===============================
some code and code2 other
29 4 14 neededx
29 4 13 neededy
29 5 10 neededz
29 4 14 neededv
My trial to solve it:
=================
regarding the heading, since it is well known i can delete it and write it once, that's OK, then i deleted the lines that are not necessary (including heading) as follows:
type filename.txt | FIND/v "PRODNA" | FIND/v "SLSTAT" | FIND/v "some" >>file2.txt
so ,now i have the file as follows:
29 4 14 ddd 208 16/3 R2C
neededx
29 4 13 ddd 208 16/3 R2C
neededy
29 5 10 2/ddd 208 459/1 R4B
neededz
29 4 14 ddd 208 16/3 R2C
neededv
the remaining is the get the fourth token from the second line not the first one, this lead to thinking about coding based on the line number (odd,even) .....but i have no more success.
your help is appreciated ,regardless if built on my trial or not.
Regards