I have these files, manually created by many different people are coming in. Formatting, although following a certain rule, is not uniform.
think of these three lines below
"erroneous_data_F08R16_recordeded_by_tech21" "erroneous_data_F8R16_recordeded_by_tech021" "erroneous_data_F008R016_recordeded_by_tech21"
they all point to the same thing F008 or F08 or F8 means File number 8 R16 or R016 or (R[single-digit] where possible) means Row number 16
There are any number of these lines in a given file, which will be scanned using
while read line loop.
What I want to do is to make the File and Row number section uniform, such as F008R016 for the above three lines of examples, as my file numbers are no more than 3 digits (it rolls over after reaching 999 and number of lines is never more than a handful in each file, but for the sake of consistency, lets say it is 3 digits. In this file I need to process, there also exists unstructured comments. So first order of business is detecting the lines and separating them in to a different temporary file, then making them uniform.
In order to accomplish this, my plan is to echo the line and grep for regex matching the pattern. Unfortunately, regex is not my strong point.
So far I am stuck at detection of the file#row# structure in the line
cat InputFile | while read line do echo $line | grep '[F,f]\d\d[R,r]\d\d' >/dev/null #this is assuming two digit file number and 2 digit row number result=$? if [ $result -eq 0 ] then echo $line >tempfile fi done
this regex matching on the grep command fails all the time, even if the line contains F08R16 pattern.
After accomplishing this, I want to extract this substring into a variable and analyze the structure of the variable and add leading zeros where necessary to make it uniform.
Any suggestions to correct my regex and accomplish my higher goal of extracting into variable, is greatly appreciated.
For what it is worth, I am working on a CentOS release 6.7 box at the time but I have other distros at my disposal.