LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   *BSD (http://www.linuxquestions.org/questions/%2Absd-17/)
-   -   awk pattern matching (http://www.linuxquestions.org/questions/%2Absd-17/awk-pattern-matching-806085/)

philipz 05-05-2010 10:07 AM

awk pattern matching
 
Guys,

I have a long text file like this:
14:10 Marc "nice guy" 14 12343
14:11 Marianne "always too late" 11 56
14:12 Marc "has long hair" 256 69
...

I want to show:
Marc 14
Marianne 11
Marc 256

I can use awk, but the problem is that the text between the quotes is variable in length. Any idea to get around this?

In the end I want to show the following:
Marc 270
Marianne 11

But first things first I guess, just added this option in case somebody would have an idea :)

Thanks for any help!

anomie 05-05-2010 03:21 PM

I'm not so sure this is a *BSD question, as much as it is an awk vs. gawk question. (And it may not even be that.)

Anyway:
Code:

> awk --version
awk version 20070501 (FreeBSD)

> cat long-text-file
14:10 Marc "nice guy" 14 12343
14:11 Marianne "always too late" 11 56
14:12 Marc "has long hair" 256 69

> awk '{ print $2, $(NF-1) }' long-text-file
Marc 14
Marianne 11
Marc 256

Based on the info you've provided, that's what I would do.


All times are GMT -5. The time now is 04:14 PM.