Grep multiple fields large file
Greetings
I have a huge file that I'm trying to extract a few fields from followed by a value. For example the file looks like this but huge, but the pattern is the same $_h7e 6ijrn3ij exceed: 8686738, string ABC/#123/in4j([99, fieldA I want to extract all matches and display like: exceed: 8686738, string ABC/#123/in4j([99, exceed: 683738, string #Pheu/GP/i972j(3i, Etc... I'm trying regex like, egrep -o "exceed: [0-9]*|string *," I'm matching exceed: and the numeric value, but not the field string and up until the comma. Suggestions please Thanks again |
Perhaps, the following?
Code:
grep -o -E 'exceed: [0-9]*|string [^,]*' Compare "man 7 regex" versus "man 7 glob" |
While I'm the self confessed #1 fan of regex solutions, maybe a simple cut ?.
Code:
cut -d ' ' -f 3-6 |
My first-blush guess here is: "greedy" vs. "non-greedy."
If you use a character like "*" in a regular expression, the default behavior is greedy. In other words, it will not stop at the first match, but will instead "greedily" stop at the last one. Which is probably not what you want in this case. For instance, the pattern (punctuation added ...) {*,} will try to find the last comma. |
Assuming the data is having set fields, you could also use awk:
Code:
awk -F'[ ,]' '/exceed/{print $3,$4","$6,$7","}' file |
Code:
grep -Eo "(exceed:|string) [^,]*" Code:
grep -Eo "exceed: [0-9]+, string [^,]*" Code:
grep -Eo "exceed: [0-9]+, string [^,]*,?" |
All times are GMT -5. The time now is 03:25 PM. |