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 06-20-2010, 10:03 AM   #1
Asteroid
LQ Newbie
 
Registered: May 2007
Posts: 27

Rep: Reputation: 15
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
 
Old 06-20-2010, 10:38 AM   #2
maxmeier12
LQ Newbie
 
Registered: Jun 2010
Posts: 4

Rep: Reputation: 0
The character you see is not \c but the control character \cI so maybe you can split("\cI", ...).
 
Old 06-20-2010, 12:13 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Asteroid View Post
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'.
 
Old 06-21-2010, 01:28 AM   #4
Asteroid
LQ Newbie
 
Registered: May 2007
Posts: 27

Original Poster
Rep: Reputation: 15
Hi, maxmeier12 Thx buddy. Ur idea worked. I replaced /c with /cI and it worked ...
 
Old 06-21-2010, 05:50 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
\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"

Last edited by bigearsbilly; 06-21-2010 at 05:51 AM.
 
  


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
[Perl] chop last char from line noir911 Programming 8 02-20-2007 10:16 PM
perl regular expression a char match richikiki Programming 8 07-19-2006 03:37 AM
Read a char from a file (PERL) linuxlover1 Programming 4 01-09-2005 09:10 AM
Perl : Changing a single char in a string richhill Programming 2 09-17-2003 04:31 PM
perl: substring extraction after specific char markus1982 Programming 2 10-06-2002 05:48 AM

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

All times are GMT -5. The time now is 06:27 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