Visit Jeremy's Blog.
Go Back > Forums > Other *NIX Forums > *BSD
User Name
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.


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

Rep: Reputation: 0
awk pattern matching


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, 03:21 PM   #2
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
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.)

> 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.


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 07:06 AM
Pattern matching in a text file - use of AWK?? wtaicken Programming 19 02-06-2009 06:54 PM
complicated pattern matching with awk or sed... alirezan1 Linux - Newbie 1 10-10-2008 07:45 PM
Help with pattern matching, sorting data with awk/gawk or perl placem Programming 2 09-11-2008 03:26 PM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 06:08 PM > Forums > Other *NIX Forums > *BSD

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

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