sed optimization


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed optimization
# 1  
Old 07-15-2009
sed optimization

I have a process using the following series of sed commands that works pretty well.
sed -e 1,1d $file |sed 1i\\"EHLO Broadridge.com" |sed 2i\\"MAIL FROM:${eaddr[0]}"|sed 3i\\"RCPT TO:${eaddr[1]}"|sed 4i\\"DATA"|sed 5s/.FROM/FROM:/|sed 6s/.TO/TO:/|sed 7,7d|sed s/.ENDDATA/./|sed s/.ENDARRAY// >temp/$file

I now need this to run much faster... I'm thinking its pretty slow because I'm calling sed so many times; but I can't figure out how to get this to run in one instance of sed... help.

Thanks
Niten
# 2  
Old 07-16-2009
i think within one sed can do it:

Code:
sed -n '2{i\
 EHLO Broadridge.com
 s/.ENDDATA/./
 s/.ENDARRAY//
 p
}
3{i\
 MAIL FROM:${eaddr[0]}
 s/.ENDDATA/./
 s/.ENDARRAY//
 p
}
...
' yourfile

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Code optimization

Hi all I wrote below code: #!/bin/sh R='\033 do you have any idea how to optimize my code ? (to make it shorter eg.) (11 Replies)
Discussion started by: primo102
11 Replies

2. Shell Programming and Scripting

CPU optimization

hi guys , I have 10 scripts suppose 1.sh , 2.sh ,3.sh ,4.sh ......10.sh each takes some time ( for instance 2 minutes to 40 minutes ) my server can run around 3-4 files at a time suppose, 1.sh , 2.sh , 3.sh are running currently now as soon as ANY ONE of the gets finished i... (4 Replies)
Discussion started by: Gl@)!aTor
4 Replies

3. Programming

Bizzare optimization problem

I have a C program that, for the life of me, I can't see any possible stack corruption in but for some reason corrupts a local variable to 0 when not referenced. My compiler is gcc 4.3.4. But my question's not really a code question, it's a compiler question. The glitch is weirdly specific: ... (3 Replies)
Discussion started by: Corona688
3 Replies

4. Shell Programming and Scripting

AWK optimization

Hello, Do you have any tips on how to optimize the AWK that gets the lines in the log between these XML tags? se2|6|<ns1:accountInfoRequest xmlns:ns1="http://www.123.com/123/ se2|6|etc2"> .... <some other tags> se2|6|</ns1:acc se2|6|ountInfoRequest> The AWK I'm using to get this... (2 Replies)
Discussion started by: majormark
2 Replies

5. 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

6. Shell Programming and Scripting

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 :: 2009-03-14 22:05:01,430 :: I need to show simply 22:01:01, 568, 181, 472 22:05:01, 903, 458, 572 that is time, TID,... (11 Replies)
Discussion started by: saifurshaon
11 Replies

7. 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

8. 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
Login or Register to Ask a Question