i am passing input parameter 'one_two' to the script , the script output should display the result as below
one_1two
one_2two
one_3two
if [ $# -ne 1 ]
then
echo " Usage : <$0> <DATABASE> "
exit 0
else
for DB in 1 2 3
do
DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}`
done
fi
---------- Post updated at 11:06 AM ---------- Previous update was at 11:04 AM ----------
throwing the below error
syntax error The source line is 1.
The error context is
{print >>> $1_${ <<<
awk: The statement cannot be correctly parsed.
The source line is 1.
Yoda
2
Correction:-
if [ $# -ne 1 ]
then
echo " Usage : <$0> <DATABASE> "
exit 0
else
DATABASE=$1
for DB in 1 2 3
do
echo $DATABASE | awk -v db=$DB -F "_" ' { print $1 "_" db "_" $2 } '
done
fi
pamu
3
Just change highlighted 3 as per your need(how many times you want to print)
if [ $# -ne 1 ]
then
echo " Usage : <$0> <DATABASE> "
exit 0
else
val=$1
echo $val | awk -F_ '{for(i=1;i<=3;i++){print $1"_"i$2}}'
fi
thanks pamu........ its working fine
There's no need for awk; use shell parameter expansion:
db=$1
for n in 1 2 3
do
dbn=${db%_*}_$n${db#*_}
echo "$dbn"
done
pamu
6
Yes, indeed we can use this.
But the time taken by awk is very less as compared the your script for higher values of n(assume more than 1000).