I have a text file as input like this:let say it as xyz.txt
TIME SR No TYPE DATA
2.046103 1 1 Tx d 8 01 01 01 99 9A 9B 9C 9D
2.046163 3 1 Rx d 8 01 01 01 99 9A 9B 9C 9D
2.046361 2 1 Rx d 8 01 01 01 99 9A 9B 9C 9D
2.046916 1 3 Tx d 8 01 01 01 9B 9C 9D 9E 9F
2.046977 3 3 Rx d 8 01 01 01 9B 9C 9D 9E 9F
2.047177 2 3 Rx d 8 01 01 01 9B 9C 9D 9E 9F
2.048034 1 5 Tx d 8 01 01 01 AD AE AF B0 B1
2.048095 3 5 Rx d 8 01 01 01 AD AE AF B0 B1
2.048295 2 5 Rx d 8 01 01 01 AD AE AF B0 B1
2.050006 1 8 Tx d 8 01 01 01 B1 B2 B3 B4 B5
2.050065 3 8 Rx d 8 01 01 01 B1 B2 B3 B4 B5
2.050265 1 8 Rx d 8 01 01 01 B1 B2 B3 B4 B5
2.050632 2 601 Rx d 8 01 01 01 CA CB CC CD CE
2.050690 3 700 Rx d 8 01 01 01 CA CB CC CD CE
2.050887 1 700 Rx d 8 01 01 01 CA CB CC CD CE
Requirement: I like to extract the first numeric strings (TIME) from lines that contains the SR “1” and TYPE as “Rx”
I hardly know perl and tried a command by reading on internet i.e:
perl -nle "print if /"1"\s(.+?)"Rx"/" xyz.txt >>output.txt
for extracting matched lines
The output i got in output.txt is:
2.046163 3 1 Rx d 8 01 01 01 99 9A 9B 9C 9D
2.046361 2 1 Rx d 8 01 01 01 99 9A 9B 9C 9D
2.050265 1 8 Rx d 8 01 01 01 B1 B2 B3 B4 B5
2.050632 2 601 Rx d 8 01 01 01 CA CB CC CD CE
2.050887 1 700 Rx d 8 01 01 01 CA CB CC CD CE
Desired output(Requirement) are only these:
2.050265
2.050887
The complete information about above two value are from xyz.txt :
2.050265 1 8 Rx d 8 01 01 01 B1 B2 B3 B4 B5
2.050887 1 700 Rx d 8 01 01 01 CA CB CC CD CE
help me….what changes i need to do, so that it will satisfy:
a. consider only “1” from Rx row and not from No row in xyz.txt file.
b. Remove all except first string in output.txt
I would avoid regexes as being hard to maintain.
Explanation:
Also, the command line switches: