How to tweak up


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tweak up
# 1  
Old 08-23-2008
How to tweak up

I have a script like this:

while read abbrev; do

sed 's/'$(echo "$abbrev" | tr "[a-z]" "[A-Z]")'/'"$abbrev"'/g' 'output_rgt.'$$ >'tmp.'$$
mv 'tmp.'$$ 'output_rgt.'$$

done<'dict.shortcuts.'$$

And I don't know how to leave "mv" out. ('dict.shortcuts.'$$ may be potentially long)

Thank you for any suggestions!

EDIT1: I know I can use two variables and save what is 'source' file and what is 'destination' file but it's not elegant too.

EDIT2:

I've rewritten it like this:

while read abbrev; do

# lookedUpAbbrev= ..
# protectedAbbred=...

echo 's/ '"$lookedUpAbbrev"'\(.*\..*\)/ {'"$protectedAbbrev"'}\1 /g;' >>'dict.commands.'$$

done<'dict.shortcuts.'$$

cat 'output_rgt.'$$ | sed -f 'dict.commands.'$$ >'tmp.'$$
mv 'tmp.'$$ 'output_rgt.'$$

Last edited by MartyIX; 08-23-2008 at 09:05 PM..
# 2  
Old 08-23-2008
I dunno. There are ways to avoid using a temporary file but sometimes temporary files are just the most robust way to get things done. Just make sure you set up the proper traps to remove the temporary when the script ends, and also if it's interrupted.
# 3  
Old 08-24-2008
Another way whitout temporary file for sed commands :
Code:
while read abbrev; do

   # lookedUpAbbrev= ..
   # protectedAbbred=...

   echo "s/$lookedUpAbbrev\(.*\..*\)/ {$protectedAbbrev}\1 /g;" 

done <'dict.shortcuts.'$$ |
sed -f -  output_rgt.$$ >'tmp.'$$
mv 'tmp.'$$ 'output_rgt.'$$

Jean-Pierre.
# 4  
Old 08-24-2008
thank you!
# 5  
Old 08-24-2008
I've adjusted the script as Jean-Pierre advised but it's still too slow:

I've a file with 480 abbreviations so that sed works with 480 substitutions and file output_rgt.$$ may have 120kB (subtitles of a movie) and it's terribly slow. Isn't there any faster way how to perform these substitions?
# 6  
Old 08-24-2008
Moving it all into a single Perl (or perhaps awk) script would reduce the overhead of spawning subprocesses to perform what seem to be fairly mundane transformations of the input. That's just a speculation, though. Can you split it up in two parts and time them? Does generating the sed script take a lot of time, and running it in sed go quickly, or is it the other way around? If the generation part dominates then I'd definitely try tackling that in Perl (and then doing the rest in Perl as well makes sense).
# 7  
Old 08-24-2008
Another thing: the bottleneck might be the regexes. Does it help if you replace .*\..* with (say) [^.]*\.[^.]* (assuming this is an acceptable trade for your scenario, of course)?
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Tar.gz help - Need to tweak

Hi Guys - I need help tweaking my tar.gz process. Currently, I compress all files in a directory, in which the parent directory is included in that. I only want to compress the "*.txt" files in the follow process: tar -zcvf ${_ESSB_TAR_PATH}/Essbase_Exports_${_DATETIMESTAMP}.tar.gz -C /... (3 Replies)
Discussion started by: SIMMS7400
3 Replies

2. Shell Programming and Scripting

Tweak python program to give result in json

Hi , Below is the script which prints result in json but when i validate it has some tab or extra space issues. JSON result { "data": } This is the line I tweaked. Please advise. print "\t{", "\"{#NAME}\":\""+container+hn+"\"}" #!/usr/bin/env python # (2 Replies)
Discussion started by: ashokvpp
2 Replies

3. Shell Programming and Scripting

Perl find command tweak

i use the following command to find files that were recently updated within the last hour: perl -MFile::Find -le' find { wanted => sub { -f and 3600 / 86400 >= -M and print $File::Find::name; } }, shift' /var/app/mydata/ this command works well. however, it seems to also search directories... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

perl line needing a tweak

Hi Folks, I have a perl line that looks like this and it works fine as is, but I need it to expand a bid further. perl -aF, -ne 'printf "conf zone %2\$s delete host %s,,,$F\n",split/\./,$F,2 if /^hostrecord/ &&/\b10\.8\.(|1)\.\d/' hosts.csv this code the way it is does this 10.8.3.0... (10 Replies)
Discussion started by: richsark
10 Replies

5. Shell Programming and Scripting

SED script needs tweak

I have a SED script that has worked for years, but broke today due to a new variable in a remote file. This is the part of the script that now won't work: sed "s|/directory/overview.gif|/directory/img/overview2.gif|g" | \ The path /directory/overview.gif is no longer static as it had been... (2 Replies)
Discussion started by: dockline
2 Replies

6. UNIX Desktop Questions & Answers

Terminal title bar tweak discrepancy problem in Cygwin/X

Code for the tweak (not my fave 'running process' but the more popular 'working directory') : case "$TERM" in xterm*|rxvt*|rxvt-unicode*) PROMPT_COMMAND='echo -e "\033]0;$TERM: ${PWD}\007"' ;; *) ;; esac Where it works: rxvt (the one I run 'rootless' outside of ... (0 Replies)
Discussion started by: SilversleevesX
0 Replies
Login or Register to Ask a Question