• 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
Shell grep help - how to get only first occurrence of match?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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

I have been trying really hard to find the proper grep syntax for what I
guess is really simple, but I just can't get it right

The text I like to grep is made up of two or more columns numbers separated
by one or more spaces. The following columns may consist of any combination
of numbers and characters .

What I need to do is to get only the first column, which unfortunately may,
or may not, begin with spaces, like this:

   12345    647890   kdghjblrttrep 9845698476 lkjlfkdj

So by writing

grep "^[0-9]*" -o

I get all the first columns of those lines that doesn't begin with spaces,
but if I try to include one of more spaces like this

grep  "^ *[0-9]*"  -o

it gives my all columns containing numbers, besides what I really want is
the numbers of the first columns but without the spaces

Can anyone please help ?



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


 _______________________________________________
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

  • Follow-Ups:
    • Re: Shell grep help - how to get only first occurrence of match?
      • From: "Mark J. Reed" <email@hidden>
    • Re: Shell grep help - how to get only first occurrence of match?
      • From: "Steven D. Majewski" <email@hidden>
    • Re: Shell grep help - how to get only first occurrence of match?
      • From: Andrei Tchijov <email@hidden>
References: 
 >Re: Shell script help - get date of last modified file in hierarchy (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Shell script help - get date of last modified file in hierarchy
  • Next by Date: Re: Shell grep help - how to get only first occurrence of match?
  • Previous by thread: Re: Shell script help - get date of last modified file in hierarchy
  • Next by thread: Re: Shell grep help - how to get only first occurrence of match?
  • Index(es):
    • Date
    • Thread