• 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: Find text with shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find text with shell script


  • Subject: Re: Find text with shell script
  • From: Axel Luttgens <email@hidden>
  • Date: Sun, 06 Aug 2006 18:08:47 +0200

On 6/08/06 13:52, dev_sleidy wrote:

Could anyone tell me the shell script that would find a line of text in a file containing a certain word? For example, if a file contained the text "MyFileName" followed by the word I wished to find, what shell command would reveal that word?

Thanks,
Garry Simon


UNIX 'grep' command.

Example 01:

do shell script "grep 'mail.gna.org/public/' /Users/s/Desktop/_123.txt"

Replace "mail.gna.org/public/" with your search string.
Replace '/Users/s/Desktop/_123.txt' with your file's full path.

Example 02:

set tString to "'mail.gna.org/public/'" -- Replace "mail .... public/" with your string.
set flle_path to "/Users/s/Desktop/_123.txt" -- Replace '/Users/s/Desktop/_123.txt' with your file's full path.


do shell script ("grep " & tString & " " & flle_path)

Perhaps would 'sed' be more appropriate with regards to Garry's original question.
For example, assuming:


   "MyFileName" is the tag announcing the word to be found,
   the tag and the word are separated by white space(s),
   the word is made of alphanumeric characters,
   the tag and the word are on a same line within the file,
   the lines in the file are delimited by newline characters,

something like this could be tried from the command line:

sed -nE 's/^.*MyFileName[[:space:]]+([[:alnum:]]*).*$/\1/p' /path/to/file

HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Find text with shell script (From: "Simon, Garry" <email@hidden>)
 >Re: Find text with shell script (From: dev_sleidy <email@hidden>)

  • Prev by Date: Re: Length of string as UTF-8
  • Next by Date: Claudio Braxmaier ist bis 21.08.2006
  • Previous by thread: Re: Find text with shell script
  • Next by thread: Claudio Braxmaier ist bis 21.08.2006
  • Index(es):
    • Date
    • Thread