Sorry didn't mean to offend anyone and thanks for the advice.
Fair enough, no problem. You are welcome.
Quote:
Originally Posted by dre
This is my attempt
So, that is a start. Let us go over it. Notice that i will address some general points about script development which may not help you for this script but in the long run.
First, you should make it a habit to declare the variables you use. Not because this is always necessary (unlike in C or other languages you can "make variables up" on the fly simply by using it) but because this is a good start to think over the algorithm you are going to employ, what information every part of it needs and so on. Furthermore you get some documentation for free.
So, let us start: you want a directory to put your results there and you want to create it. Question: what should happen if the directory already exists, i.e. from a former run of the script? Use it again? Create a new one? Overwrite the files there? Number the files so that results from diferent runs can exist alongside?
Second: this is a typo:
Don't worry - typos happen to all of us. But wouldn't it be nice to avoid such typos? Actually you can, by using a variable instead of a fixed name. And, by the way, is it really a good idea to put the directory in the current directory? Wouldn't it be better to create a directory in your HOME, regardless of where you currently are when you call the script? So, how about doing it like this:
You see, now you can use "$targetdir" in your script and if you want to change the location you will have to do it only in one place - and it is easy to understand where that is because of the comment! Well written scripts are easy to read and easy to maintain.
Another point: don't use "cd" in a script! Use absolute pathes so that the script works regardless of where you stand. or from where you call it always in the same way.
you actually do not need the first line because the redirection will create the (empty) file if it doesn't exist. Adding the path (instead of the "cd") we get:
Let us pause here, it is getting quite late for me. More on the script tomorrow, but you might want to go over the question above and us what you wnat the script to do. Further, you may want to explain what your script does not do or does wrongly. Finally, a bit more information about your environment: OS, version, .... - might also help because some systems have special provisios others do lack.
I have a very basic bash shell script, which has many "while... done; for .... done" loop clauses, like the following
~~
#!/bin/bash
while blablalba; do
....
done < /tmp/file
for line in `cat blablabla`; do grep $line /tmp/raw ; done > /tmp/1;
while blablalba2; do
....
done <... (2 Replies)
SEND_MESSAGE=test
echo $SEND_MESSAGE
if
then
echo `date` > update_dt_ccaps.lst
echo "The file transfer failed" >> update_dt_ccaps.lst
SEND_MESSAGE=false
fi
The above code is showing error in bash shell as :
./test: line 5: [: test: integer expression expected
... (2 Replies)
I'm trying to search all .odt files in a directory for a string in the text of the file.
I've found a bash script that works, except that it can't handle whitespace in the filenames.
#!/bin/bash
if ; then
echo "Usage: searchodt searchterm"
exit 1
fi
for file in $(ls *.odt); do
... (4 Replies)
Hi,
I am working on bash script after a long time. I am getting error near done statement while running a for loop snippet. The error says "Syntax error near unexpcted token 'done'"
please suggest what could be wrong. here is the snippet
elements=${#option_arr} //an array of values... (1 Reply)
Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass).
Here is... (0 Replies)
Hi Folks,
I have a loop that goes through an array and the output is funky.
sample:
array=( 19.239.211.30 )
for i in "${array}"
do
echo $i
iperf -c $i -P 10 -x CSV -f b -t 50 | awk 'END{print '$i',$6}' >> $file
done
Output:
19.239.211.30
19.2390.2110.3 8746886
seems that when... (2 Replies)
I have the following while loop that I put in a script, demo.sh:
while read rna; do
aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed)
echo "$aawork" | sed 's/ //g'
echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/*\(*\) \(.*\)/\2: \... (3 Replies)
Hi Everybody,
I'm a newbie to shell scripting, and I'd appreciate some help. I have a bunch of .txt files that have some unwanted content. I want to remove lines 1-3 and 1028-1098.
#!/bin/bash
for '*.txt' in <path to folder>
do
sed '1,3 d' "$f";
sed '1028,1098 d' "$f";
done
I... (2 Replies)
Dear all,
Please help with the following.
I have a file, let's call it data.txt, that has 3 columns and approx 700,000 lines, and looks like this:
rs1234 A C
rs1236 T G
rs2345 G T
Please use code tags as required by forum rules!
I have a second file, called reference.txt,... (1 Reply)
Hi everyone
I need some help
I want to create an script which does some processing
it takes the two arguments 201901010000 and 201901020200 - so YYYMMDDHHMM
I want to split processing into hours from start until end,
I dont get why this works but when I add to a future variable... (1 Reply)