Perl scripting to get "Wanted Data"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl scripting to get "Wanted Data"
# 1  
Old 05-18-2014
Perl scripting to get "Wanted Data"

I have data like below :

Source file : input.txt ( so many data with same format )

Code:
09.05.2014 09.49.52:359 RID:routerNode1@app1:1662306081,msisdn:787887225696,sid:93889095007001,tid:1405090902095648846024000,status:2,time:20140509094952,reason:DELIVRD,refund:null,status2:null

output1.txt
Code:
09.05.2014,09.49.52,routerNode1@app1:1662306081,787887225696,93889095007001,1405090902095648846024000,2,20140509094952


output2.txt

Code:
09-05-2014,09-49-52,routerNode1@app1:1662306081,787887225696,93889095007001,1405090902095648846024000,2,20140509094952



Please advice me to build the perl program to read from input file dan write to output file


Thank you very much.
TIA

Last edited by bartus11; 05-18-2014 at 06:33 AM.. Reason: Please use [code][/code] tags.
# 2  
Old 05-18-2014
Remove the red line to keep the dots, rather than dashes:
Code:
perl -F'\s|,' -ane '$\=",";
	for $i (0..$#F) {
		@s=split(/:/,$F[$i]);
		if($i<=1) {
			$s[0]=~s/\./-/g;
			print $s[0].($i==1? $\="":"")
		}
		else {
			if($#s==2) {print ",$s[1]:$s[2]"}
			else {print ",$s[1]" if $s[1]!=0}
		}
	}
print "\n" if not eof' input.txt

# 3  
Old 05-18-2014
Thank Jethrow ...

09.05.2014 09.49.52:073 RID:routerNode1@cdmsapp1:1662691809,msisdn:9875434355,sid:34500116008034,tid:zd330106074,status:2,time:20140509094952,reaso
nSmilieELIVRD,refund:null,status2:null

the output :

09-05-2014,09-49-52,routerNode1@cdmsapp1:1662691809,9875434355,34500116008034,2,20140509094952

is it numeric for TID(column) ? if alphanumeric, the TID is missing.
how make it alphanumeric ?


and for the last line, how to print "\n", so the output make it perfect.

09-05-2014,09-49-52,routerNode1@cdmsapp1:1662712526,765433456,46500112042005,1927536832,96,20140509094952[user1@app1 current]$
# 4  
Old 05-18-2014
Quote:
Originally Posted by MacLing66
Thank Jethrow ...

09.05.2014 09.49.52:073 RID:routerNode1@cdmsapp1:1662691809,msisdn:9875434355,sid:34500116008034,tid:zd330106074,status:2,time:20140509094952,reaso
nSmilieELIVRD,refund:null,status2:null

the output :

09-05-2014,09-49-52,routerNode1@cdmsapp1:1662691809,9875434355,34500116008034,2,20140509094952

is it numeric for TID(column) ? if alphanumeric, the TID is missing.
how make it alphanumeric ?


and for the last line, how to print "\n", so the output make it perfect.

09-05-2014,09-49-52,routerNode1@cdmsapp1:1662712526,765433456,46500112042005,1927536832,96,20140509094952[user1@app1 current]$
Substitute the red for the green if you still want to make that code to work per your last comment.

Code:
perl -F'\s|,' -ane '$\=",";
	for $i (0..$#F) {
		@s=split(/:/,$F[$i]);
		if($i<=1) {
			$s[0]=~s/\./-/g;
			print $s[0].($i==1? $\="":"")
		}
		else {
			if($#s==2) {print ",$s[1]:$s[2]"}
			#else {print ",$s[1]" if $s[1]!=0}
                        else {print ",$s[1]" if $s[1] =~ /\d/}
		}
	}
#print "\n" if not eof' input.txt
print "\n"' input.txt

# 5  
Old 05-19-2014
this command not work.

print "\n"' input.txt
692027007001,D6076688,2,2014050909495209-05-2014,09-49-52,routerNode1@cdmsapp1:1662712508,6285727810567,46500112042005,1927536822,4,2014050909495209-05-2014,09-49-52,routerNode1@cdmsapp1:1662712509,6285729318319,46500112042005,1927536823,4,2014050909495209-05-2014,09-49-52,routerNode1@cdmsapp1:1662712526,6285788820370,46500112042005,1927536832,96,20140509094952./noel.sh: line 15: unexpected EOF while looking for matching `''
./noel.sh: line 16: syntax error: unexpected end of file

the data is OK.


another request is like below :

19.05.2014 09.38.58:448 23780325241 INFO {Process:7:90}[RID:routerNode1@cdmsapp1:1712743012,555555555555]RULEZ [EMM] Charge successful charge:2000, msisdn:555555555555, a_number:959907, service_id:95990265063007, ResponseDeltaTime:166 ms, subscribertypeSmiliere

19.05.2014 09.38.58:449 23780325286 INFO {Process:7:168}[RID:routerNode1@cdmsapp1:1712821878,77777777777]RULEZ [EMM] Charge failed msisdn:77777777777, a_number:268091, service_id:26800153034011, res:7, err:End_user_service_denied, ResponseDeltaTime:207 ms, subscribertypeSmiliere


wanted data :

19-05-2014,09-38-58,routerNode1@cdmsapp1:1712743012,Charge successful,555555555555,959907,95990265063007,166 ms,pre

19-05-2014,09-38-58,routerNode1@cdmsapp1:1712821878,Charge failed,77777777777,268091,26800153034011,7,207 ms,pre


Please help me again.

Thank you.
# 6  
Old 05-19-2014
Please post some concrete requests. You keep changing the source data. Or, better yet, how about learning from the posted code & adapting it to meet your needs?
# 7  
Old 05-19-2014
Hi Jethrow,

right now there is 3 format :

1.
Code:
09.05.2014 09.49.52:359 RID:routerNode1@app1:1662306081,msisdn:787887225696,sid:93889095007001,tid:1405090902095648846024000,status:2,time:20140509094952,reason:DELIVRD,refund:null,status2:null

2.
Code:
19.05.2014 09.38.58:448 23780325241 INFO  {Process:7:90}[RID:routerNode1@cdmsapp1:1712743012,555555555555]RULEZ  [EMM] Charge successful charge:2000, msisdn:555555555555,  a_number:959907, service_id:95990265063007, ResponseDeltaTime:166 ms,  subscribertype:pre


3.
Code:
19.05.2014 09.38.58:449 23780325286 INFO  {Process:7:168}[RID:routerNode1@cdmsapp1:1712821878,77777777777]RULEZ  [EMM] Charge failed msisdn:77777777777, a_number:268091,  service_id:26800153034011, res:7, err:End_user_service_denied,  ResponseDeltaTime:207 ms, subscribertype:pre

sorry to make you confuse.

Last edited by Franklin52; 05-19-2014 at 06:31 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

Perl failure with "main::$fn" used only once:" in error logs

Hi all, Can anyone guess why this is happening? I am new to Perl, so please help me to fix this error: - I have a static html file which calls the cgi-perl script. HTML Code: <html> <head> <title> Hey Dude! </title> </head> <body> <form method="POST"... (3 Replies)
Discussion started by: bashily
3 Replies

5. Shell Programming and Scripting

perl - Removing dots(".") from the data

Hi Friends, I have a file1 as below file1.txt 100000.||1925-01-10|00:00|1862SHERMA NAVE#1SE.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670 100001.||1935-01-10|00:00|1862NEW . YRK NO.||EVTON|IL|60201||22509.|BDSS|62007|2639.|26670. 100002.||1965-01-10|00:00|1862 IND . INC,CL... (6 Replies)
Discussion started by: i150371485
6 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

perl folder list with "..", without ".".

Hi Everyone, if my folder "foldera" inside has one file. so if i do if ($df =~ /^\./) { next; } then i will get ### filea ### if i want to have ### .. filea ### means also display the parent .., how should i modify the perl ~// in my code? Thanks ---------- Post updated... (6 Replies)
Discussion started by: jimmy_y
6 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question