Re: Find text with shell script
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