LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-12-2010, 09:43 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
regex escape the comma


sometimes there are one, sometime there are two exchanges in this log file. the 100= is the stock exchange- if there are two, they are seperated by a comma.
i understand how to \ escape a comma in a regex, but I am having trouble with combining it.


35=8 39=1 38=1000 32=13 14=754 31=1.11 44=1.1 100=AMEX,ISE
35=8 39=1 38=1000 32=151 14=205 31=1.1 44=1.1 100=AMEX
35=U 39=2 38=1000 32=45 14=184 31=1.1 44=1.1 100=AMEX,ISE
35=U 39=2 38=1000 32=45 14=574 31=1.1 44=1.1 100=AMEX
35=U 39=2 38=1000 32=45 14=734 31=1.1 44=1.1 100=AMEX,ISE
35=U 39=2 38=1000 32=45 14=704 31=1.1 44=1.1 100=AMEX,ISE
35=U 39=2 38=1000 32=45 14=794 31=1.1 44=1.1 100=AMEX
35=U 39=2 38=1000 32=45 14=484 31=1.1 44=1.1 100=AMEX
35=8 39=1 38=1000 32=0 14=905 31=0.00 44=1.1 100=AMEX,ISE
35=8 39=1 38=1000 32=44 14=949 31=1.11 44=1.1
35=U
35=8 39=4 38=1000 32=0 14=949 31=0.00 44=1.1 100=ISE

zgrep 00072224.0000f5d1.4c60d592 fixaudit.eprop323.20100810.002815.gz | perl -ne 'print /(100=[\w]*\,[\w]* )/ | sort
100=AMEX,ISE
100=AMEX,ISE
100=AMEX,ISE
100=AMEX,ISE
100=AMEX,ISE
zgrep 00072224.0000f5d1.4c60d592 fixaudit.eprop323.20100810.002815.gz | perl -ne 'print /(100=[\w]*)/ | sort
100=AMEX
100=AMEX
100=AMEX
100=AMEX
100=AMEX
100=AMEX
100=AMEX
100=AMEX
100=AMEX
100=ISE

What I want is

100=AMEX,ISE
100=AMEX
100=AMEX.ISE
100=AMEX
100=AMEX,ISE
100=AMEX,ISE
100=AMEX
100=AMEX
100=AMEX,ISE
100=ISE
 
Old 08-12-2010, 09:48 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
What makes you think a comma needs escaping? It has no special meaning
in any regex flavour I'm aware of.

Anyway ... I think what you want is:
Code:
zgrep 00072224.0000f5d1.4c60d592 fixaudit.eprop323.20100810.002815.gz | perl -ne 'print /(100=[\w]+,*[\w]*)/ | sort

Last edited by Tinkster; 08-12-2010 at 09:51 PM.
 
Old 08-12-2010, 09:52 PM   #3
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Does it have to use perl?
Code:
awk '/100=/{print $NF}'
And why were you running it through `sort`? the result you say you want, is not sorted.
 
Old 08-12-2010, 09:55 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
And - as I'm not a perlite, I'm curious: are you two both missing a single quote, or should that work for me with only one single quote (because it doesn't)?
 
Old 08-12-2010, 10:03 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,406

Rep: Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396Reputation: 2396
Code:
@arr=split(/\s+/, $rec);
if( scalar(@arr) == 8 )
{  
    print "$arr[7]\n";
}
 
Old 08-12-2010, 11:56 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by GrapefruiTgirl View Post
And - as I'm not a perlite, I'm curious: are you two both missing a single quote, or should that work for me with only one single quote (because it doesn't)?
You're quite right :}

I just copied & pasted and changed the regex
 
Old 08-12-2010, 11:57 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by GrapefruiTgirl View Post
Does it have to use perl?
Code:
awk '/100=/{print $NF}'
And why were you running it through `sort`? the result you say you want, is not sorted.

But that would (as 100 is 1000) also print
Code:
35=8 39=1 38=1000 32=44 14=949 31=1.11 44=1.1


Cheers,
Tink
 
Old 08-13-2010, 02:01 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Quote:
Originally Posted by Tinkster
But that would (as 100 is 1000) also print
Maybe if the 1000 had an equals sign (=) inserted as the second last character.
 
Old 08-13-2010, 11:49 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Right you are, and I am blind.

Apologies, Sasha!
 
Old 08-14-2010, 06:02 AM   #10
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Ehh, no worries Tink :-) there was a printf statement I had been using way back sometime in some code or other (when I didn't really know what printf even was) and it actually made use of a single single-quote, deliberately.. So, there are cases.

Anyhow, I'm still curious about the `sort` command the OP uses here, since his desired output is in the same order as they were in the input; maybe if the OP could comment on what everyone's posted here? Does any of this work as desired?
 
Old 09-12-2010, 01:08 PM   #11
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
I use the sort because the log file is 10,000 lines and it prints out the answers line by line - the sort makes sure that they are at the end of the command prompt - not spaced out over a few screens.
 
Old 09-12-2010, 01:09 PM   #12
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Tinkster View Post
Right you are, and I am blind.

Apologies, Sasha!
THanks tink
 
  


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
[SOLVED] pyqt3 list without comma? gary_in_springhill Programming 1 03-21-2010 05:05 PM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 05:50 PM
comma operator in C cleopard Programming 16 04-25-2008 09:57 AM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM
Comma key doesn't work mengkai Linux - Laptop and Netbook 1 03-05-2004 11:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration