unfortunately, this is what i see in my terminal:
Please wait while the task completes
/bin/sh: Syntax error: Unterminated quoted string
pipe nan%
/home/bj/Desktop/Final_JCATS_userin2.sh inf%
can anybody out there see what i'm doing wrong? I'm pretty sure that the error is in the awk portion of the script, considering it wasn't there prior to the addition of it. Thanks!
That was by far the quickest reply I have every gotten on a forum. I really appreciate it aigles!!!
unfortunately, now i'm getting this error. I apologise if it's something simple. I'm still new to scripting and trying to feel my way through.
./Final_JCATS_userin2.sh: line 110: unexpected EOF while looking for matching `"'
./Final_JCATS_userin2.sh: line 114: syntax error: unexpected end of file
Here is everything i have in my script right now...
#!/bin/bash
echo
echo "This script will find a string in the JCATS .fplan file and replace the next line with"
echo "the next line with info from a csv file."
echo "Written by Brian Biller with help from the internets Nov 2009"
echo
echo "Please enter the name of the fplan you would like to change"
cnt=0
while true
do
read -r fplan
if [[ -f "$fplan" || -f ../"$fplan" ]]
then
echo "File exists"
break
else
echo "Try again"
fi
((cnt+=1))
if [[ $cnt -eq 5 ]]
then
echo "exceeded 5 tries. quitting"
exit
fi
done
echo
echo "Please enter the name of the csv file you would like to import from"
cnt=0
while true
do
read -r csv
if [[ -f "$csv" || -f ../"$csv" ]]
then
echo "File exists"
break
else
echo "Try again"
fi
((cnt+=1))
if [[ $cnt -eq 5 ]]
then
echo "exceeded 5 tries. quitting"
exit
fi
done
echo
echo "Please enter the string you would like to replace"
read -r string
echo
echo "Please wait while the task completes"
lsof -o0 -o -p $$ |
awk '
BEGIN { CONVFMT = "%.2f" }
$4 ~ /^[0-9]+r$/ && $7 ~ /^0t/ {
offset = substr($7, 3)
fname = $9
"stat -f %z " Q fname Q | getline
len = $0
print fname, offset / len * 100 "%"
}
' Q="'"
sleep 5
I=1
while read -r LINE
do
if [[ "${LINE}" =~ "SystemDeclarationData" ]] #~ this is the first string to search for. constant unless the parameters change
then
echo "$LINE"
read -r LINE #~ if the string on the next line has the string needing replaced then replace it with the string in line 1.
if [[ ${LINE} =~ "$string" ]]
then
head -n$I $csv | tail -n1
(( I ++ )) #~ the next instance of the pattern would be replaced by the string in line 2 and so on.
else echo "$LINE"
fi
else echo "$LINE"
fi
done < "$fplan" > $PWD/complete
sleep 5
echo
echo
echo "backing up original fplan"
cp "$fplan" "$fplan".bak
sleep 5
echo
echo "renaming the changed file to work with jcats"
mv $PWD/complete "$fplan"
sleep 3
echo
echo "operation completed"
echo
echo