The awk
regex
below produces the current,where
only the matching line are printed. However, I am trying to print all lines in test.txt
,
and if the line matches the first regex
the word "good" is printed after the line.
If the line does matches the second regex
the word "test" is printed after the line.
If the line does not match the regex
the word "bad" is printed after the line.
I'm not sure the best way to accomplish the desired but the logic is:
regex1
1. ensure each line begins with 00-0000
2. followed by -some number
3. followed by -case insensitive male or female-BBB_xxx
4. string of all Caps_
regex 2
1. starts with ani digits
2. followed by - case insensitive test_
test.txt
00-0000-1234-Male-BBB_xxx.txt
11-1111_xxx.txt
00-0000-12345-female-BBB_xxx.txt
000000-Test_xxx.txt
awk '/^[0-9][0-9]-[0-9][0-9][0-9][0-9]-[[:digit:]]+-[Mm]ale|[Ff]emale-[A-Z]_*/' test.txt && awk '/^[[:digit:]]+-[Tt]est_*/'test.txt
current
00-0000-1234-Male-BBB_xxx.txt
00-0000-12345-female-BBB_xxx.txt
000000-Test_xxx.txt
desired
00-0000-1234-Male-BBB_xxx.txt good
11-1111_xxx.txt bad
00-0000-12345-female-BBB_xxx.txt good
000000-Test_xxx.txt test