Sponsored Content
Top Forums Programming String Manipulation in a text file Post 302763643 by John Trevor on Wednesday 30th of January 2013 09:03:30 AM
Old 01-30-2013
String Manipulation in a text file

Hi

I have a requirement to write a script but not sure which is the best way to approach this

I have not worked in sed but I'm aware that its robust for file extraction requirements

I have a scripting task. I already developed the code in perl but the script is taking almost 2 mins for execution . (Input file size is almost 5 MB).
I believe this can be done in a better way using awk or sed.
Which is the best way to approach this ?

Expecting expert advise from the awk and sed gurus here


Requirement in Detail:
a) Capture all the Ticket IDs from a text file in a linux box
Ticket ID will be the 16 digit string (beginning with TT) after the string "TicketNumber===>" (highlighted in red in the sample input file content below)

b)Based on each Ticket Id, search the entire file and calculate the response time delays (difference of the date and time fields at the beginning of each line) for every alert

eg: For 00000052605, the requirement is to pull the delay b/w Request and Response Time for (highlighted in red in the sample input file content below)

1)acknowledged
2)assigned
3)analyse
4)Task Set

Also, It's not necessary that the line containing the Request log text should be followed by the the Response log text. .Multiple Alarm info could be mixed up..Ticket ID is the the only unique field..

c) Finally, the delays for each alert should be saved into another file in csv format

Let me know if you need any other relevant info

Sample Input File:

Code:
28 Jan 2013 21:45:22,279: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Create ticket Request===> 1359431122 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:26,710: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Create ticket Response===> 1359431126 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:27,256: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> TicketNumber===> 000000052605 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:27,731: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket State Change Request===> TT-000000052605 openactive.assigned 1359431127 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:30,328: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket State Change Response===> TT-000000052605 openactive.assigned 1359431130 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:32,633: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket State Change Request===> TT-000000052605 openactive.acknowledged 1359431132 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:34,608: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket State Change Response===> TT-000000052605 openactive.acknowledged 1359431134 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:35,093: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket State Change Request===> TT-000000052605 openactive.analyzed 1359431135 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:37,021: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket State Change Response===> TT-000000052605 openactive.analyzed 1359431137 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:37,477: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket - Task Set Request===> TT-000000052605 1359431137 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111
28 Jan 2013 21:45:39,688: [TEP_CreateTicket][MessageProcessor-Dog#8]Parser log: T3E===> Ticket - Task Set Response===> TT-000000052605 1359431139 Trap Forwarder on server01 HCL-INFRA on 192.168.1.9 RJ741RJ 903 environmentfailureevent Minor 1359431111

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Text file manipulation

Hi, I need to remove lines from a text file that are less than certain length in UNIX. For example, test.txt file contains the following lines: abcdefghijklmnopqrstuvwxyz. 123456789009876543211234567 This line to be removed. zyxwvutsrqponmlkjihgfedcba. The length of each line is supposed... (5 Replies)
Discussion started by: svannala
5 Replies

2. UNIX for Dummies Questions & Answers

Text file manipulation

I am a new unix user & I wanted to work with unix as it is very good in text manipulations. I need a little help. I will be grateful if someone can help me out. I need help in grepping a pattern of numbers from one file to another file. Specific details are as follows: File one contains only... (4 Replies)
Discussion started by: Ezy
4 Replies

3. Shell Programming and Scripting

String manipulation in a file

I have a text file having number of different rows like this.. Action & Adventure|Whiteout| Kids Free|PBS KIDS Sprout|En espanol| Kids Free|PBS KIDS Sprout|En espanol|XYZ| Basically,i want to read the file and write to another file in a tree structure like this.. each row should have 6... (7 Replies)
Discussion started by: ramse8pc
7 Replies

4. Shell Programming and Scripting

File text manipulation

What I am trying to do is make a script that will add a port number within a section of a file if it already doesn't exist in that section of the file. The particular line that I would like to add the port number to in the file is formatted like this: TCPPORTS="25 80 125 443 8080 10000" For... (3 Replies)
Discussion started by: nullifx
3 Replies

5. Shell Programming and Scripting

Text File Manipulation

Hi, I need to write shell script for the scenario explained below - datafile.txt AcctNum,code,Region,,,, 12345451,AN ,abaab 12345452,AN ,xccxc 76677545,RP ,acxcc 43567878,RP ,afghh 32190900,AN ,afrfrf 87312345,AN ,aqaw I have a text file (datafile.txt)... (1 Reply)
Discussion started by: ravigupta2u
1 Replies

6. UNIX for Dummies Questions & Answers

Text File Manipulation Help

Hi I've two text files FILE_1 and FILE_2 as shown below: FILE_1.txt CO Contig1 342 12 11 U GGGCTGACGTGGCCGCTAATACGACTCACTATAGGG*AGAGAAGTCATTTTCTTGTTTAG BQ 35 35 35 50 50 50 50 50 50 50 50 60 65 65 65 65 65 65 65 65 65 65 65 65 50 AF GP5UOVN01AOPE0 U 1 AF GP5UOVN01AT8W3 U 1 ... (1 Reply)
Discussion started by: Fahmida
1 Replies

7. Shell Programming and Scripting

Awk to convert a text file to CSV file with some string manipulation

Hi , I have a simple text file with contents as below: 12345678900 971,76 4234560890 22345678900 5971,72 5234560990 32345678900 71,12 6234560190 the new csv-file should be like: Column1;Column2;Column3;Column4;Column5 123456;78900;971,76;423456;0890... (9 Replies)
Discussion started by: FreddyDaKing
9 Replies

8. UNIX for Dummies Questions & Answers

Mathematical manipulation of a text file

I have a tab delimited file with 4 columns. If the value in the first column, equals the value in the second column, I'd like to have the 4th column multiplied by 2 then add 1. If the value in the first column differs from the value in the second, I'd like to have the 4th column multiplied by 2... (5 Replies)
Discussion started by: evelibertine
5 Replies

9. Shell Programming and Scripting

Text file manipulation

Hi Gurus, I have a question I have a flat file like below with three fields (3 rd field is amt) ad|B|500 cc||100 dd|C|600 ee||900 Need to write a code in such a way that when second field is empty then do sum of third field So in this case it will be 100 +900 I tried but no luck... (1 Reply)
Discussion started by: patricjemmy6
1 Replies

10. UNIX for Dummies Questions & Answers

Text File Manipulation

Hello, Supposing I had a huge list as follows: TAC manufacturer Device Type 1392600 LG D959 LG-D959TS FeaturePhone 1409700 LG V410 FeaturePhone 35150806 LG F350S FeaturePhone 35165206 Samsung GT-E1200 FeaturePhone 35194505 Nokia Asha 200 FeaturePhone but I want to make it look like... (3 Replies)
Discussion started by: Cludgie
3 Replies
All times are GMT -4. The time now is 07:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy