Perl code- word count problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl code- word count problem
# 1  
Old 09-07-2011
Perl code- word count problem

Hi,

I am having .csv files contains some row -

Code:
Info: Value of field name 'SecurityExchange' is not supported ","Original Order Tuple[ ORDI_
 
Info: Value of field name 'SecurityExchange' is not supported ",Original Order Tuple[
 
Info: Instrument not found for defined Symbol and MIC  ",Original Execution Tuple[ testJ


Please see the below perl code carefully-

Code:
/Info: ([^,]+),Original (\w+) Tuple/ and do {
   ($category, $type) = ($1, $2);
   if($type eq 'Execution') {
        $sb_exec++;
   } else {
       $sb_ord++;
   }


In above case i am getting an output $sb_exec is 1 which is right

and $sb_ord is 1 which should be 2

it is because of Before Original word some rows contain "Original and some rows contain only Original ...it does not contain double qotes(").

Please help me to solve this issue , how can i ignore double quotes before Original word


Thanks in advance

Moderator's Comments:
Mod Comment Use code tags, please!
# 2  
Old 09-07-2011
Quote:
Originally Posted by pspriyanka
...
Code:
Info: Value of field name 'SecurityExchange' is not supported ","Original Order Tuple[ ORDI_
 
Info: Value of field name 'SecurityExchange' is not supported ",Original Order Tuple[
 
Info: Instrument not found for defined Symbol and MIC  ",Original Execution Tuple[ testJ

...
Code:
/Info: ([^,]+),Original (\w+) Tuple/ and do {
   ($category, $type) = ($1, $2);
   if($type eq 'Execution') {
        $sb_exec++;
   } else {
       $sb_ord++;
   }

...
and $sb_ord is 1 which should be 2

it is because of Before Original word some rows contain "Original and some rows contain only Original ...it does not contain double qotes(").
...
how can i ignore double quotes before Original word
...
Moderator's Comments:
Mod Comment Use code tags, please!

Code:
$
$
$ cat f13
Info: Value of field name 'SecurityExchange' is not supported ","Original Order Tuple[ ORDI_
Info: Value of field name 'SecurityExchange' is not supported ",Original Order Tuple[
Info: Instrument not found for defined Symbol and MIC  ",Original Execution Tuple[ testJ
$
$
$ perl -lne '/Info: ([^,]+),"*Original (\w+) Tuple/ and do {
               ($category, $type) = ($1, $2);
               if ($type eq 'Execution') {
                 $sb_exec++;
               } else {
                 $sb_ord++;
               }
             };
             END {print "$sb_exec, $sb_ord"}
            ' f13
1, 2
$
$

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

3. Shell Programming and Scripting

perl count lines with certain word int

Hi Guys I have a text file that contains the message like this /var/log/messages.all-20120401: Mar 26 12:12:23 brent kernel: NVRM: Xid (0003:00): 43, 0005 00009097 00000000 00000000 00001b0c 1000f010 /var/log/messages.all-20120401: Mar 27 20:42:40 brent kernel: NVRM: Xid (0003:00): 43,... (4 Replies)
Discussion started by: ab52
4 Replies

4. Shell Programming and Scripting

Perl code Out of memory problem

Hi I am working with a 3.0 GB file and running the following script to process it. After running for 15 minutes, the script stops saying Out of memory or Killed. Can the experts suggest where my code can be improved to save memory? Thanks in advance. #! usr/bin/perl use warnings; open... (3 Replies)
Discussion started by: polsum
3 Replies

5. Shell Programming and Scripting

extract whole thing in word, leaving behind last word. - perl

Hi, i've a string /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD/TESi T_11_HD_120/hd-12 i need to get string, like /u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD the words from HD should get deleted, i need only a string till HD, i dont want to use any built in... (4 Replies)
Discussion started by: asak
4 Replies

6. Shell Programming and Scripting

perl (word by word check if a hash key)

Hi, Now i work in a code that 1-get data stored in the database in the form of hash table with a key field which is the " Name" 2-in the same time i open a txt file and loop through it word by word 3- which i have a problem in is that : I need to loop word by word and check if it is a... (0 Replies)
Discussion started by: eng_shimaa
0 Replies

7. Shell Programming and Scripting

Word count of lines ending with certain word

Hi all, I am trying to write a command that can help me count the number of lines in the /etc/passwd file ending in bash. I have read through other threads but am yet to find one indicating how to locate a specifc word at the end of a line. I know i will need to use the wc command but when i... (8 Replies)
Discussion started by: warlock129
8 Replies

8. Fedora

word count wc

could someone explain this please. echo aaaa|wc -c 5 echo aaaa|wc -m 5 But I'd expect the count to be 4 Its SunOS 5.8 Thanks in Advance. (5 Replies)
Discussion started by: chaandana
5 Replies

9. Shell Programming and Scripting

grep all records in a file and get a word count -perl

Hi, I have a file .. file.txt .. i need to get a total record count in the files into a $variable.. im using perl script thanks (4 Replies)
Discussion started by: meghana
4 Replies

10. UNIX for Dummies Questions & Answers

Word count problem

I have a text file that has 5719 rows when I open it up in a text editor. When I do a wc -l in Unix however, it says that I have 5718 rows. What could be causing this difference? (1 Reply)
Discussion started by: ssmith001
1 Replies
Login or Register to Ask a Question