Hi Guys,
I found this code in net.. it is working fine..
But can anybody explain me the sed statement used in the code..
echo "Enter the expression:\c"
read express
eval echo "$express"|sed 's/^/'$precision' \
/'|bc -l|\
sed -n '1,${
/syntax/!{
}
/syntax/{
a\
Possible causes:\
1. Error in expression\
2. Variable not enclosed in (), supplied -ve value\
3. Exponents given as non-integers
}
s/\([ ]*\)\([^ ]*\)/\2/p
}'
Thanks For your help in advance..
Regards,
Magesh
---------- Post updated 02-02-10 at 12:40 AM ---------- Previous update was 02-01-10 at 08:35 PM ----------
Guys come on man.. i was counting on you people
Hi,
I'm learning sed with:
Sed - An Introduction and Tutorial
So:
Ask for expresion:
echo "Enter the expression:\c"
read express
Appended some precision variable (must have been definited before) and run through bc (calculator)
eval echo "$express"|sed 's/^/'$precision' \
/'|bc -l|\
Don't print anything if not request by /p argument (-n switch) on every line (1,$).
sed -n '1,${
If no "syntax" in line was found - don't print nothing.
/syntax/!{
}
For lines that do contain "syntax" word:
/syntax/{
... append more explanation:
a\
Possible causes:\
1. Error in expression\
2. Variable not enclosed in (), supplied -ve value\
3. Exponents given as non-integers
}
Finally, print the word first word (string/digits) of lines which are starting with whitespaces. I guess this is a format of bc final result.
s/\([ ]*\)\([^ ]*\)/\2/p
}'
Not bad for an hour of reading, I guess. Please correct me if I'm wrong - I'm just learning.
Thanks man.. really appreciated.