Script Optimization required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Optimization required
# 1  
Old 03-16-2009
Script Optimization required

Dear All,
Sorry to bother you. But I tried the below problem but didn't come up a good solution. A have a file containing such info

2009-03-14 22:01:01,430 :: [TID:568][REFID:09031422000000958][MNO:181][NW:AK][TT:472][INSTR:1237046400958][INEND:1237046401430]
2009-03-14 22:05:01,430 :: [TID:903][REFID:09031422000000958][MNO:458][NW:AK][STG:TOP][TT:572][INS:1237046400958][INEND:1237046401430]

I need to show simply
22:01:01, 568, 181, 472
22:05:01, 903, 458, 572

that is time, TID, MNO, TT

i tried it with

x=1;
while [ $x -le $linecount ]
do
singleline=`sed "${x}q;d" $inputfile`
dttime=`echo $singleline | cut -d "," -f 1`

singleline=`echo $singleline|cut -d "," -f 2|awk '{print $3}'`

echo $singleline|awk '{gsub("\\[|\\]",":");print}'|awk -F: '{print $dttime","$3","$9","$18}'

x=`expr $x + 1`
done

But it doesn't show the correct result. Would you please look?
# 2  
Old 03-16-2009
Code:
#  sed 's/[^ ]* \([^,]*\),.*TID:\([0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' infile
22:01:01, 568, 181, 472
22:05:01, 903, 458, 572

HTH
# 3  
Old 03-17-2009
this solution is superb. but one problem in regular expression. that is if
TID:T009.998.3333 like this
then this code is not working?
# 4  
Old 03-17-2009
Quote:
Originally Posted by saifurshaon
this solution is superb. but one problem in regular expression. that is if
TID:T009.998.3333 like this
then this code is not working?
then try like this..
Code:
 
sed 's/[^ ]* \([^,]*\),.*TID:\([0-9]*.[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g'  file

# 5  
Old 03-17-2009
Code:
sed 's/^.*\([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*TID:\([0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*$/\1,\2,\3,\4/' filename

# 6  
Old 03-17-2009
I don't know why it is not working. every thing is okay but ..

2009-03-14 22:00:03,420 :: [TID:F090314.20.209][REFID:09031422000200999][MNO:1812513180][NW:AK][STG:TOP][TT:420][INSTRTIME:1237046402999][INENDTIME:1237046403419]
2009-03-14 22:00:03,431 :: [TID:F090314.022.2021][REFID:09031422000300098][MNO:1817220980][NW:AK][STG:TOP][TT:332][INSTRTIME:1237046403098][INENDTIME:1237046403430]


sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' file.txt
# 7  
Old 03-17-2009
Quote:
Originally Posted by saifurshaon
I don't know why it is not working. every thing is okay but ..

2009-03-14 22:00:03,420 :: [TID:F090314.20.209][REFID:09031422000200999][MNO:1812513180][NW:AK][STG:TOP][TT:420][INSTRTIME:1237046402999][INENDTIME:1237046403419]
2009-03-14 22:00:03,431 :: [TID:F090314.022.2021][REFID:09031422000300098][MNO:1817220980][NW:AK][STG:TOP][TT:332][INSTRTIME:1237046403098][INENDTIME:1237046403430]


sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g' file.txt
sed 's/[^ ]* \([^,]*\),.*TID:\(*[0-9]*.[0-9]*.[0-9]*\).*MNO:\([0-9]*\).*TT:\([0-9]*\).*/\1, \2, \3, \4/g'
you have inserted one extra * in that
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need Optimization shell/awk script to aggreagte (sum) for all the columns of Huge data file

Optimization shell/awk script to aggregate (sum) for all the columns of Huge data file File delimiter "|" Need to have Sum of all columns, with column number : aggregation (summation) for each column File not having the header Like below - Column 1 "Total Column 2 : "Total ... ...... (2 Replies)
Discussion started by: kartikirans
2 Replies

2. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

3. Shell Programming and Scripting

Script Optimization - large delimited file, for loop with many greps

Since there are approximately 75K gsfiles and hundreds of stfiles per gsfile, this script can take hours. How can I rewrite this script, so that it's much faster? I'm not as familiar with perl but I'm open to all suggestions. ls file.list>$split for gsfile in `cat $split`; do csplit... (17 Replies)
Discussion started by: verge
17 Replies

4. Shell Programming and Scripting

Awk script gsub optimization

I have created Shell script with below awk code for replacing special characters from input file. Source file has 6 mn records. This script was able to handle 2 mn records in 1 hr. This is very slow speed and we need to optimise our processing. Can any Guru help me for optimization... (6 Replies)
Discussion started by: Akshay
6 Replies

5. Shell Programming and Scripting

Looking for optimization advice on a short script

I already have a solution to my problem, but I'm looking to see if it can be made more succinct and faster. The problem: given a list, as shown below, extract the pathname for any file in a directory named 'ample' and return it's index into the list. The index is also in the data itself. Note that... (1 Reply)
Discussion started by: prigo
1 Replies

6. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

7. UNIX for Dummies Questions & Answers

unix script optimization

I have a file which contains 9,200,000. It contains 125 clolumns. I have to rearrange some columns and exclude some of them. I scripted the following script to do the same. It is working fine but it is taking more than 4hrs to do it. can it be optmized. Here is the script LOC="/sourcefile/"... (3 Replies)
Discussion started by: max_payne1234
3 Replies

8. Shell Programming and Scripting

script optimization

:o Hi, I am writing a script in which at some time, I need to get the process id of a special process and kill it... I am getting the PID as follows... ps -ef | grep $PKMS/scripts | grep -v grep | awk '{print $2 }'can we optimize it more further since my script already doing lot of other... (3 Replies)
Discussion started by: vivek.gkp
3 Replies

9. UNIX for Dummies Questions & Answers

Help on optimization of the script

Hi, I have prepared script which is taking more time to process. find below script and help me with fast optimized script:- cat name.txt | while read line do name=$(echo $line| awk '{print $8}') MatchRecord=$(grep $name abc.txt | grep -v grep ) echo "$line | $MatchRecord" | awk... (2 Replies)
Discussion started by: aju_kup
2 Replies

10. Shell Programming and Scripting

script required

The line is like this +abc+def+mgh+ddsdsd+sa i.e. words seperated by +. There is a plus in the beginning. i want to conver this line to abc, def, mgh, ddsdsd, sa please provide the logic in the form of a shell script Thanks in advance (13 Replies)
Discussion started by: skyineyes
13 Replies
Login or Register to Ask a Question