Need help optimizing this piece of code (Shell script Busybox)
I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox.
Example of data:
$SORTEDTMP= it is a file created using find that contain all the movies (200+) on my drive. ex:
/USB/movies/science-fiction/alien/alien.avi
/USB/movies/comedy/funnymovie/funnymovie.avi
....etc
Movieinfo = Just an xml file containing data about the movie; I only care about extracting the movie title if the file exist vs using the filename as the movie title which may or may not be accurate.
All the other jpg, bmp may or may not exist and appropriate action are taken based on their existence.
Currently the created xml file is being appended for every movies that match the grep MOVIESPATH which could include all the movies. This part of the code is called up many times to create an xml files for all the different movie category including "All movies". I am not sure if I can store all the data in a temporary place in memory and before I leave this loop write the file would be faster ????? I don't know and do not have much experience.
So I'll ask again does anyone sees anything there that could be optimized that would significantly increase the running speed of this piece of code.
Code:
grep "$MOVIESPATH" $SORTEDTMP | while read plik
do
MovieName=`basename "$plik" | sed 's/\(.*\)\..*/\1/'`
DirectoryPath=`dirname "$plik"`
if [ -e "$DirectoryPath/MovieInfo.nfo" ];
then
MOVIEINFO="$DirectoryPath/MovieInfo.nfo"
MOVIETITLE=`grep "<title>.*<.title>" "$MOVIEINFO" | sed -e "s/^.*<title/<title/" | cut -f2 -d">"| cut -f1 -d"<"`
else
MOVIETITLE=$MovieName
fi
if [ -e "$DirectoryPath/folder.jpg" ];
then
MOVIEPOSTER=$DirectoryPath/folder.jpg
elif [ -e "$DirectoryPath/${MovieName}.jpg" ];
then
MOVIEPOSTER=$DirectoryPath/${MovieName}.jpg
else
MOVIEPOSTER=/usr/local/etc/srjg/nofolder.bmp
fi
if [ -e "$DirectoryPath/about.jpg" ];
then
MOVIESHEET=$DirectoryPath/about.jpg
elif [ -e "$DirectoryPath/0001.jpg" ];
then
MOVIESHEET=$DirectoryPath/0001.jpg
elif [ -e "$DirectoryPath/${MovieName}_sheet.jpg" ];
then
MOVIESHEET=$DirectoryPath/${MovieName}_sheet.jpg
else
MOVIESHEET=/usr/local/etc/srjg/NoMovieinfo.bmp
fi
echo -e '<Movie>
<title>'$MOVIETITLE'</title>
<poster>'$MOVIEPOSTER'</poster>
<info>'$MOVIESHEET'</info>
<file>'$plik'</file>
</Movie>' >> $RSS
done
use "getopts" to get params from command. Need replace black with a specified string like "%20
DEFAULT_DELIM=%20
...
while getopts dek:f:t:vh OPTION
do
case $OPTION in
t)
DELIM=`tvar=/'"$OPTARG"'/ svar="$DEFAULT_DELIM" awk 'BEGIN{T=ENVIRON;S=ENVIRON; while(index(T,S)!=0){S=S"0"};print... (0 Replies)
Hi All,
I am trying to understand and change some code written by some programmer a while ago. There are following three lines of code that I am unable to grasp. Could anybody please help me understand it?
1) cd - > /dev/null
2) fname=`basename "$1"` where $1 = /dirA/dirB/a.txt
... (3 Replies)
hi fndz.
Can you please help me with the code if I call a stored procedure from my shell script and stored procedure returns a cursor,
cursor output should be saved to a file (3 Replies)
Hi,
Does anybody know how to enable the shell sh while creating Ramdisk fs using BusyBox? while creating a configuration using the GUI, I see options only for the ash shell. Is there some option in the config file that gets created with which I can enable the sh shell also apart from the ash... (0 Replies)
Hello -- I am trying to learn to do a little sed and awk scripting to search for text and numbers in text files (text processing/manipulation). My professor gave me a piece of uncommented code and I am very unfamiliar w/ the language. Can someone help me with comments so I can understand what is... (2 Replies)
Hi,
I have two files in the format listed below. I need to find out all values from field 12 to field 20 present in file 2 and list them in file3(format as file2)
File1 :
FEIN,CHRISTA... (2 Replies)
Hi All,
I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder.
But... (5 Replies)
Hi,
I need to remove first column from a csv file and i can do this by using below command.
cut -f1 -d, --complement Mytest.csv
I need to implement this in shell scripting, Whenever i am using the above command alone in command line it is working fine.
I have 5 files in my directory and... (3 Replies)
I have prepared a shell script to find the duplicates based on the part of filename and retain latest.
#!/bin/bash
if ; then
mkdir -p dup
fi
NOW=$(date +"%F-%H:%M:%S")
LOGFILE="purge_duplicate_log-$NOW.log"
LOGTIME=`date "+%Y-%m-%d %H:%M:%S"`
echo... (6 Replies)
Discussion started by: gold2k8
6 Replies
LEARN ABOUT DEBIAN
kino
KINO(1) General Commands Manual KINO(1)NAME
kino - non-linear editing of Digital Video data
SYNOPSIS
kino [ ( file | playlist ) ... ]
DESCRIPTION
kino allows you to import movies from DV camcorders, to edit, and play them. file may be a DV encoded file that will be loaded at startup.
Alternatively, you can specify a SMIL playlist of DV files that was previously created with kino.
DV is a special kind of video encoding, commonly used in digital camcorders. Differently coded movies, like DivX or mjpeg, need to be con-
verted to DV before they can be fed into kino.
A video file either holds the raw DV-coded data, or wraps it in a certain container format. Kino currently supports AVI, and QuickTime con-
tainers, and distinguishes between the different formats by file extension. Therefore, file names need to end in .dv or .dif for raw
files, .avi for AVI, and .mov for QuickTime files, respectively. Anything else is treated as a SMIL playlist.
KEYSTROKES
Unlike other editors, kino uses many keyboard commands for fast navigation and editing inside the movie. It acts on frames that are single
images from a movie, scenes that are defined as groupings of one or more frames with recording times differing by no more than one second,
and movies that are groups of one or more scenes. The following keystrokes can be used for moving and editing. Some of them are also avail-
able as buttons in a graphical menu bar. (Also note the deliberate similarities between kino commands and the text editor vi.) The follow-
ing is a brief list of the commands. A more complete list is available in the online help.
MOVING AROUND
space Toggle between play and pause.
l, right-arrow
Move one frame forward.
h, left-arrow
Move one frame backward.
gg Move to the start of the movie.
G Move to the end of the movie.
0, ^ Move to the start of the current scene.
$ Move to the end of the current scene.
j, return, +, down-arrow
Move to the start of the next scene.
k, -, up-arrow
Move to the start of the previous scene.
ctrl-f Move forward five scenes.
ctrl-b Move backwards five scenes.
w Move forward one second.
b Move backwards one second.
DELETE OPERATIONS
x, dl, d space, del
cut the current frame.
dd cut the current scene.
d$ cut from current frame to end of scene.
d^, d0 cut from start of scene to before current frame.
dG cut to end of movie.
dgg cut from beginning of movie.
CLONE OPERATIONS
yl, y space
copy the current frame.
yy, Y copy the current scene.
y$ copy from current frame to end of scene.
y^, y0 copy from start of scene to current frame.
INSERT OPERATIONS
p paste after current frame.
P paste before current frame.
GENERAL COMMANDS
:r inserts a SMIL playlist or DV AVI before frame. (Pops up a file dialog.)
:w saves the movie as a SMIL playlist. (Pops up a file dialog.)
:q quits the program.
SEE ALSO
the kino online help, kino2raw(1), dvgrab(1)AUTHORS
kino was written by Arne Schirmacher <arne@schirmacher.de>, Dan Dennedy <dan@dennedy.org>, and Charles Yates <charles.yates@pandora.be>.
This manual page was originally written by Daniel Kobras <kobras@debian.org> for the Debian GNU/Linux system (but may be used by others).
January 2004 KINO(1)