I have a File which looks like this
example text [1234] [0] Part 2 /var/tmp/path
example text [1234] [0] Part 3 /var/tmp/path
example text [1234] [0] Some Text more text
example text [1235] [0] Part 4 /var/tmp/path
example text [1235] [0] Part 5 /var/tmp/path
example text [1236] [0] Part 6 /var/tmp/path
example text [1236] [0] other text foo bar
Part 2
Part 4
Part 6
1234
1235
1236
grep -F -f parts.txt search.log
Here is one way to do it.
myparts=$(grep -F -f parts.txt search.log | awk -F'[][]' '{print $2}' | sort | uniq)
parts.txt is the file that users write part numbers in.
grep returns the lines where part number matches.
awk uses [
and ]
as delimiters to extract the first word between them