I am trying to write a script to get all the html files under a source directory and and for each html file, run a program with html file as an argument. This program generates an output which I need to save as htmlfilename.txt ( right now i was trying to print it on the command line)
SOURCE_DIR=/a/b/c
#location of program
EXE_DIR=/d/f/g
for htmlfile in 'find $SOURCE_DIR \( -name *.html \)';
do
output=$($EXE_DIR/program "$htmlfile");
echo $output;
echo "Printing the expected output" ;
done
What am I doing wrong? I am not getting any output.
Also How do you assign the output of a command to a variable?
And how do you redirect the output to a file with a specific name?
Using of find is unnecessary, to select the html files you can do something like:
SOURCE_DIR=/a/b/c
#location of program
EXE_DIR=/d/f/g
for htmlfile in "$SOURCE_DIR"/*.html
do
output=$("$EXE_DIR"/program "$htmlfile")
echo "$output"
done
I was trying to use 'Find' as my My SOURCE_DIR have mulitple directories and which in turn have html and other files. For example:
SOURCE_DIR= /a/b/c
-c has subdirectories h , d, f and g
-subdirectories h and d has few html files
-f and g has more subdirectories and the subdirectories might have html files
----
for htmlfile in "$SOURCE_DIR"/*.html
----
This works only if SOURCE_DIR have html file.
ok I think I need help here.
I need to redirect the output to a file with the same name and location as html file
for htmlfile in "$SOURCE_DIR"/*.html
do
$($EXE_DIR"/program "$htmlfile") >> output file
## where putput file = htmlfile.txt""
echo "$output"
doneWhat should I use to create the name of the output file similar to html file?
Can I use sed to copy the location and name of .html file and create a new .txt file with the same name and at the same location?
For example:
output=program "a/b/d/f/123.html"
redirect output to a/b/d/f/123.txt
take note of spaces in filenames when using the for loop with find. you can work around by changing IFS, do some quoting, or simply use the while read loop instead
find ..... | while read FILE
do
# do something with $FILE
done
Vbe
I cant directly output in a file as $htmlfile has a extension of .html ( for example it $htmlfile = a/b/c/d/123.html ) , I need to create a .txt file with the same name and on the same location, so I want a/b/c/d/123.txt
"So the output of a/b/c/d/123.html should go to a/b/c/d/123.txt"
if i use
>>$EXE_DIR/$htmlfile.txt
the name of the file will be a/b/c/d/123.html.txt
isn't it?
Thanks!
--------------
vbe wrote:
Why want to copy?
Is there a reason why you cannot directly output to the file, to the correct location
e.g. >>$EXE_DIR/$htmlfile.txt
1 Day Ago 12:07 AM