Tag Archives: VAL

Adding a specified value to a specified column – awk?

By radudownload

Hi everyone!

I sometimes need to do some simple arithmetics, like adding a number to a certain column of a file. So I wrote a small function in the .bashrc file, which looks like this

Code:

shifter()
{
COL=$1
VAL=$2
FILE=$3

cp $FILE $FILE.shifted
awk 'NF==4 {$(( $COL )) = $(( $COL )) + $VAL}' $FILE.shifted
}


which should add the number stored in VAL, to the column COL from the FILE file.

Please give me a hint how should I make this work. Thank you! (I’m just a newbie in shell programing)

…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

How to execute functions or initiate functions as command line parameters for below requirement?

By saku

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line

if [ “$VAL” == “1” ]
then
fun1
elif [ “$VAL” == “2” ]
then
fun2
elif [ “$VAL” == “3” ]
then
fun3
elif [ “$VAL” == “4”]
then
fun4
elif [ “$VAL” ==” 5″ ]
then
fun5
elif [ “$VAL” == “6” ]
then
fun6
elif [ “$VAL” == “7” ] then
fun7
else
echo -e “Invalid input………….n”
Help
exit
fi

OR

case “$VAL” in
“1”)
fun1
;;
“2”)
fun2
;;
“3”)
fun3
;;
*)
echo -e “Invalid input………….n”
;;
esac

Source: FULL ARTICLE at The UNIX and Linux Forums