#!/bin/sh
INPUT () {
echo "Please enter line number: "
read LINE
echo "Please enter column number that you want to modify: "
read COLUMN
head -$LINE dataf > line1;
LINE=`expr $LINE + 1`
head -$LINE dataf > line2;
diff line1 line2 > tmp;
sed -e 's/;/ /g' tmp > tmp2;
COLUMN=`expr $COLUMN + 1`
OLDV=`awk '{printf "%s\n",$'$COLUMN' ; }' tmp2`
echo "The value is $OLDV \n"
echo "Please enter new value of the column: "
read NEWV
sed -e 's/$OLDV/$NEWV/g' tmp2 > tmp3
}
OthersMod () {
echo "Do you want to do other modifications [y/n]?"
read ANS
while [ "$ANS" = y ]
do
INPUT
OthersMod
done
}
INPUT
OthersMod
This is the whole script. The problem is:
echo "Please enter new value of the column: "
read NEWV
sed -e 's/$OLDV/$NEWV/g' tmp2 > tmp3
I can't change the old value to the new value. Any wrong with the script?? Please help.. THANKS!
Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.
For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.
Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.
If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.
Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.
#!/bin/sh
INPUT () {
echo "Please enter line number: "
read LINE
echo "Please enter column number that you want to modify: "
read COLUMN
head -$LINE dataf > line1;
LINE=`expr $LINE + 1`
head -$LINE dataf > line2;
diff line1 line2 > tmp;
sed -e 's/;/ /g' tmp > tmp2;
COLUMN=`expr $COLUMN + 1`
OLDV=`awk '{printf "%s\n",$'$COLUMN' ; }' tmp2`
echo "The value is $OLDV \n"
echo "Please enter new value of the column: "
read NEWV
sed 's/'`echo "$OLDV"`'/'`echo "$NEWV"`'/g' tmp2 > tmp3
cat tmp3
}
OthersMod () {
echo "Do you want to do other modifications [y/n]?"
read ANS
while [ "$ANS" = y ]
do
INPUT
OthersMod
done
}
INPUT
OthersMod
are you sure the error message is for this double quoted sed and not the for the previous sed you have in the function..? Make sure the first sed command (sed -e 's/;/ /g' tmp > tmp2;) works fine and yields the expected output.
The script in post #10 just needed the awk corrected to repair the error seen from the corrected "sed" (the one with double quotes).
The whole script has dubious logic and we need to know what it is meant to do.