$cat bearish.htm | awk 'NR>3'
Thursday, January 22, 2009
while statement
C-style while loop:
#!/bin/bash # wh-loopc.sh: Count to 10 in a "while" loop. LIMIT=10 a=1 while [ "$a" -le $LIMIT ] do echo -n "$a " let "a+=1" done # No surprises, so far. echo; echo # +=================================================================+ # Now, repeat with C-like syntax. # Double parentheses permit space when setting a variable, as in C. ((a = 1)) # a=1 # Double parentheses, and no "$" preceding variables. while (( a <= LIMIT )) do echo -n "$a " ((a += 1)) # Double parentheses permit incrementing a variable with C-like syntax. done exit 0 # +=================================================================+ # reading a file line by line while read line do echo "${line}" done < ./straddle.prop
Posted by
techgeek168
at
8:43 AM
0
comments
Labels: UnixBashVi
case statement
case $1 in
-s) sec=1; shift;;
-m) sec=60; shift;;
-h) sec=3600; shift;;
-d) sec=86400; shift;;
*) sec=86400;;
esac
Posted by
techgeek168
at
8:42 AM
0
comments
Labels: UnixBashVi
Float/Real Number Comparison
if [ $( echo "5.5 > 10.5" | bc ) -eq 1 ]; then
echo 5.5 is greater than 10.5.
else
echo 5.5 is NOT greater than 10.5.
fi
=> 5.5 is NOT greater than 10.5.
Posted by
techgeek168
at
8:41 AM
0
comments
Labels: UnixBashVi
Regular Expression in if in bash script
if echo "4567" | grep -q "^4"; then
echo "4567 is started with a 4."
elif echo "4567" | grep -q "^A"; then
echo "4567 is started with a A."
else
echo "4567 is NOT started with a 4 or A."
fi
Posted by
techgeek168
at
8:41 AM
0
comments
Labels: UnixBashVi
Get Create Table statement from MySQL
$ sql "show create table my_table\G" | sed -e '1,2d;s/Create Table: //'
Note: sed -e '1,2d' removes the first 2 lines.
Posted by
techgeek168
at
8:40 AM
0
comments
Labels: Database
Change Prompt
$
$ PS1="myPrompt> "
myPrompt>
myPrompt>
Posted by
techgeek168
at
8:39 AM
0
comments
Labels: UnixBashVi