LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices

Reply
 
Search this Thread
Old 05-05-2010, 09:07 AM   #1
philipz
LQ Newbie
 
Registered: Apr 2004
Posts: 25

Rep: Reputation: 0
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!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-05-2010, 02:21 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
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.
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pattern matching vinaytp Linux - Newbie 2 10-10-2009 06:06 AM
Pattern matching in a text file - use of AWK?? wtaicken Programming 19 02-06-2009 05:54 PM
complicated pattern matching with awk or sed... alirezan1 Linux - Newbie 1 10-10-2008 06:45 PM
Help with pattern matching, sorting data with awk/gawk or perl placem Programming 2 09-11-2008 02:26 PM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM


All times are GMT -5. The time now is 09:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration