LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-29-2005, 12:24 AM   #1
fhleung
Member
 
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Rep: Reputation: 30
"^" meaning in perl/shell script?


Does anyone know what is meaning of "^" symbol in perl/shell script?
 
Old 12-29-2005, 12:37 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
in a regex?

like
Code:
foreach (@myinput){
    print $1 if /^(foo)/;
}
in that usage it means the beginning of a string.. so in that line foo has to be at the beginning.. if there is anything before foo it does not match..

if used as an operator i think it is xor..
 
Old 12-29-2005, 12:48 AM   #3
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
in a regular expression if '^' is used in a bracket grouping, ex. [^a-d], it means match anything that's not in the brackets. So in the example, match anything that's not a,b,c, or d.
 
Old 12-29-2005, 12:49 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
yup.. forgot that one.. and probably not only that one..
 
Old 12-29-2005, 02:03 AM   #5
fhleung
Member
 
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Original Poster
Rep: Reputation: 30
Could you quote more examples using this with grep please?

Thnak you so much for the help!
 
Old 12-29-2005, 02:08 AM   #6
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
http://www.gnu.org/software/grep/doc/grep_7.html#SEC7
Your specific usage is on this page: http://www.gnu.org/software/grep/doc/grep_8.html#SEC8
Be sure to click the Back (<) and Forward (>) buttons to read the tutorial.

Last edited by scuzzman; 12-29-2005 at 02:09 AM.
 
Old 12-29-2005, 02:13 AM   #7
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
well, you can do 'man grep' as there is a regular expression tut in there. I'm not a guru with regex (I use them, but my usage experience is pretty limited), but i believe there are some differences between perl regex and grep regex.
 
Old 12-31-2005, 11:58 AM   #8
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
Originally Posted by megaspaz
well, you can do 'man grep' as there is a regular expression tut in there. I'm not a guru with regex (I use them, but my usage experience is pretty limited), but i believe there are some differences between perl regex and grep regex.
The main difference is in the metacharacters you have to escape - perl tends to do things the "other way round" to grep regexps, usually because the deemed "more common usage" has fewer keystrokes in perl. Can be confusing if you use both a lot!
 
Old 01-03-2006, 08:27 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,818

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
As mentioned in this book Mastering Regular Expressions by Jeffrey E. F. Friedl, the various tools eg sed/grep/perl etc, each have their own internal regex engines, which are similar, but not identical, so care is needed at all times.
 
  


Reply


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
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 03:11 AM
err on running "perl -MCPAN -e shell" wellblue88 Linux - Newbie 0 09-21-2004 02:43 PM
Reconfigure command in "perl -MCPAN -e shell" asciimonster Linux - Software 1 09-16-2004 09:48 AM
Compiling KDE 3.2.0 - "Can't open perl script "/dcopidlng/kalyptus" linuxgamer09483 Linux - Software 3 04-09-2004 09:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:00 PM.

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