ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My "Old Brain" syndrom is acting up again. I fixed this same kind of an issue once before but do you think I can figure out how? No.
I need to access a line in a csv file by the first field in the line. That field contains something like 16:Sun the day number and the day name.
I have commands that work when I run them by hand but they don't work in the script as posted below.
Code:
# Yom Tove reading setup
# Needs YOMTOVE DAY MONTH YEAR TZ LONG LAT passed in
function YTReading_Setup {
if echo $YOMTOVE | grep 'Pesach' ;then
CURENTDAY="$( hdate -q --not-sunset-aware $DAY $MONTH $YEAR | awk '{print $5;}' )"
read DAYNAME< <(date -d $YEAR-$MONTH-$DAY +%a)
echo "$CURRENTDAY"
echo "$DAYNAME"
READING=$(grep ^ "$CURENTDAY:$DAYNAME" "$STORDIR"/Pesach.csv)
echo "$READING"
DAYSREADING="$($CURENTDAY:$DAYNAME)"
else READING=$(grep ^"$YOMTOVE" "$STORDIR"/YomTove.csv)
DAYSREADING="${YOMTOVE// /}"
fi
READTIME="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
IFS=, read -a arr <<<"$READING"
for ALIYAH in "${arr[@]:3:11}";do
ARRAY=( 95 100 105 110 115 120 125 )
SPEED=$(shuf -n1 - < <(printf "%s\n" "${ARRAY[@]}"))
ARRAY2=( m1 m2 m3 m4 m5 m6 m7 f1 f2 f3 f4 f5 f6 f7 )
SPEAKER=$(shuf -n1 - < <(printf "%s\n" "${ARRAY2[@]}"))
COMMAND="espeak -s "$SPEED" -ven-us+"$SPEAKER""
# Generate AND append to action file
echo "$COMMAND -f $STORDIR/$ALIYAH &" >> "$TMPDIR/$DAYSREADING"
done
at "$READTIME" "$MONTH/$DAY/$YEAR" -f "$TMPDIR/$DAYSREADING"
}
When run it returns this. As can be seen when $CURENTDAY is proccesed, in this case 21, it is ading a ' to the output, as in 21' so when the $READING is proccessed it does not find 21:Fri because now it contains an extra character and that is not in the csv and it is packing the whole csv into $READING
I have tried adding and removing both single and double quotes and searched online but have not rediscoverd how I fixed this problem just the other week.
I know it is something simple but I can't find it. Any help?
That fixed it but now I have a different issue. The saved file names have a ? prepended to them and they contain a : which I think is bad. Will have to look into it.
OK so I got rid of the : out of both the generated file name and the cvs file data because I thought it was as special character but that did not fix the issue. I am still seeing the add ' to the search string that is used to grep the csv file.
Is there a better way to assign the values to $CURENTDAY & $DAYNAME? $CURENTDAY must contain the Hebrew day number while $DAYNAME needs to contain the short day name as in Tue.
And then $READING is pulling the entire csv file in as its data instead of just the line for the specific date/day as it I intended. When it generates the 'at' job it always uses the data from line one in the csv file. I have removed all blank lines from the csv also.
Code Section:
Code:
# Yom Tove reading setup
# Needs YOMTOVE DAY MONTH YEAR TZ LONG LAT passed in
function YTReading_Setup {
if echo $YOMTOVE | grep 'Pesach' ;then
CURENTDAY="$( hdate -q --not-sunset-aware $DAY $MONTH $YEAR | awk '{print $5;}' )"
read DAYNAME< <(date -d $YEAR-$MONTH-$DAY +a)
# echo "$CURENTDAY"
# echo "$DAYNAME"
READING=$(grep ^"$CURENTDAY$DAYNAME" "$STORDIR"/Pesach.csv)
# echo "The reading is $READING"
DAYSREADING="$CURENTDAY$DAYNAME"
else READING=$(grep ^"$YOMTOVE" "$STORDIR"/YomTove.csv)
DAYSREADING="${YOMTOVE// /}"
fi
READTIME="$(hdate -t -L$LONG -l$LAT -z$TZ $DAY $MONTH $YEAR | awk '/sunrise/{print $2}')"
IFS=, read -a arr <<<"$READING"
for ALIYAH in "${arr[@]:3:11}";do
ARRAY=( 95 100 105 110 115 120 125 )
SPEED=$(shuf -n1 - < <(printf "%s\n" "${ARRAY[@]}"))
ARRAY2=( m1 m2 m3 m4 m5 m6 m7 f1 f2 f3 f4 f5 f6 f7 )
SPEAKER=$(shuf -n1 - < <(printf "%s\n" "${ARRAY2[@]}"))
COMMAND="espeak -s "$SPEED" -ven-us+"$SPEAKER""
# Generate AND append to action file
echo "$COMMAND -f $STORDIR/$ALIYAH &" >> "$TMPDIR/$DAYSREADING"
done
at "$READTIME" "$MONTH/$DAY/$YEAR" -f "$TMPDIR/$DAYSREADING"
}
:~$ hdate -q --not-sunset-aware 05 04 2015
Sunday, 5 April 2015, 16 Nisan 5775
:~$
yes there is a blank line
On a different note what does the ^ do in READING=$(grep ^"$CURENTDAY$DAYNAME" "$STORDIR"/Pesach.csv) I have looked in the man for grep but didn't find it. I saw it online somewhere but now I can't find it. On top of that I misplaced my grep reference book. :{
On a different note what does the ^ do in READING=$(grep ^"$CURENTDAY$DAYNAME" "$STORDIR"/Pesach.csv) I have looked in the man for grep but didn't find it. I saw it online somewhere but now I can't find it. On top of that I misplaced my grep reference book. :{
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.