LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PERL \c char (https://www.linuxquestions.org/questions/programming-9/perl-%5Cc-char-815278/)

Asteroid 06-20-2010 10:03 AM

PERL \c char
 
Hi guys, I am stuck up in a situation. I have a SUN box with certain logs which I need to parse to draw a report using Perl.

Now, when I load the text file using a perl degugger to see how the text looks like when the first line of the log file is read in a variable. below is the snapshot of first line read from the file. My usefull values are like ITS=20100620082137,409 cIOTS=20100620082137,691. It seems \c is the character which could be used as value seperator.

Code:

"ITS=20100620082137,409\cIOTS=20100620082137,691\cIUSER=untrustedapp\cIOP=GetSubscriptionStatus\cIRC=1000\cIMSISDN=966501237533\cISID=61\cIDATA_CLI={SUBSCRIPTIONTYPE=10}\cIDATA_RES=\cI\cI"

So, I tried to split the values using the split function but Its not working. Any idea about this "\c" char and how can I manage to split the text in my text file.

Code:

@values = split('\c', $item);
Moreover, when I cat my log file the /c char is not visible rather the values are seperated by spaces as below.


Code:

ITS=20100620102817,341  OTS=20100620102817,603  USER=untrustedapp      OP=GetSubscriptionStatus        RC=1000 MSISDN=966535468329

maxmeier12 06-20-2010 10:38 AM

The character you see is not \c but the control character \cI so maybe you can split("\cI", ...).

Sergei Steshenko 06-20-2010 12:13 PM

Quote:

Originally Posted by Asteroid (Post 4009356)
Hi guys, I am stuck up in a situation. I have a SUN box with certain logs which I need to parse to draw a report using Perl.

Now, when I load the text file using a perl degugger to see how the text looks like when the first line of the log file is read in a variable. below is the snapshot of first line read from the file. My usefull values are like ITS=20100620082137,409 cIOTS=20100620082137,691. It seems \c is the character which could be used as value seperator.

Code:

"ITS=20100620082137,409\cIOTS=20100620082137,691\cIUSER=untrustedapp\cIOP=GetSubscriptionStatus\cIRC=1000\cIMSISDN=966501237533\cISID=61\cIDATA_CLI={SUBSCRIPTIONTYPE=10}\cIDATA_RES=\cI\cI"

So, I tried to split the values using the split function but Its not working. Any idea about this "\c" char and how can I manage to split the text in my text file.

Code:

@values = split('\c', $item);
Moreover, when I cat my log file the /c char is not visible rather the values are seperated by spaces as below.


Code:

ITS=20100620102817,341  OTS=20100620102817,603  USER=untrustedapp      OP=GetSubscriptionStatus        RC=1000 MSISDN=966535468329


First find our the ASCII code of what is seen as '\c' - use 'ord' function for that:

perldoc -f ord

; you'll probably need 'substr' too:

perldoc -f substr
.

When you're done with that, it will be pretty obvious how to write 'split'.

Asteroid 06-21-2010 01:28 AM

Hi, maxmeier12 Thx buddy. Ur idea worked. I replaced /c with /cI and it worked ...

bigearsbilly 06-21-2010 05:50 AM

\cI = ctrl-I is a TAB.

also,

if you use single quotes in perl it won't substitute value

"\n" is a newline
'\n' is literally two characters '\' and 'n'

try split "\cI" or better, split "\t"


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