• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Shell grep help - how to get only first occurrence of match?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shell grep help - how to get only first occurrence of match?


  • Subject: Re: Shell grep help - how to get only first occurrence of match?
  • From: Richard Rönnbäck <email@hidden>
  • Date: Sat, 31 Mar 2007 17:34:12 +0200
  • Thread-topic: Shell grep help - how to get only first occurrence of match?

Thank you all!

I decided to use awk, but the other suggestions will also come in handy for
the project I am working on so this was even more helpful than I expected
:-)

Thanks again!


-------------------------------------------------
Richard Rönnbäck
Publishing-konsult
email@hidden
Helsingörsgatan 24
164 44 KISTA
SWEDEN
+46 (0) 8 444 06 08
+46 (0) 70 774 06 08
-------------------------------------------------


> Från: Walter Bushell <email@hidden>
> Datum: Wed, 28 Mar 2007 22:02:36 -0400
> Till: "email@hidden :applescript users"
> <email@hidden>
> Ämne: Re: Shell grep help - how to get only first occurrence of match?
>
> The man pages were written for people who already know what the
> commands  For "awk" this is more true than most Eunichs commands..
>
>
> On Mar 28, 2007, at 8:18 PM, Malcolm Fitzgerald wrote:
>
>>
>> On 29/03/2007, at 3:57 AM, Mark J. Reed wrote:
>>
>>> If you have columns of data separated by arbitrary amounts of
>>> whitespace, the command you're looking for is awk, rather than grep.
>>>
>>> awk '{print $1}' will print the first column of every line.  $2 for
>>> the second, etc.
>>> $NF (short for "Number of Fields") for the last column, $(NF-1) for
>>> the second-to-last, etc.
>>> $0 is the whole line.
>>>
>>> you can stick /pattern/ in front of the {...} block to run it only
>>> for
>>> lines matching that pattern, e.g.
>>>
>>> awk '/[0-9]/ {print $1}'  will print the first column of all lines
>>> that contain a digit anywhere in the line.  Note that this means
>>> it is
>>> never necessary to do grep | awk. :)
>>
>>
>> Wow, it's that easy. You wouldn't know it from the man page.
>>
>> malcolm
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> AppleScript-Users mailing list      (applescript-
>> email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>> 40panix.com
>> Archives: http://lists.apple.com/archives/applescript-users
>>
>> This email sent to email@hidden
>>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> edband.net
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: Shell grep help - how to get only first occurrence of match? (From: Walter Bushell <email@hidden>)

  • Prev by Date: Re: Keystroke in AppleScript
  • Next by Date: Re: alias list error
  • Previous by thread: Re: Shell grep help - how to get only first occurrence of match?
  • Next by thread: Re: Shell grep help - how to get only first occurrence of match?
  • Index(es):
    • Date
    • Thread