I want to change the second column to upper case and I want to do it in shell script only. (no one liners!)
#!/bin/sh
# read file line by line
file="/pdump/country.000000.txt"
while read line
do
mycol=`echo $line | awk -F"," '{print $2}'`
mycol_new=`echo $mycol | tr "[:lower:]" [:upper:]`
echo $line | awk -F"," '{print $1 "," $mycol_new "," $3 "," $4 "," $5 "," $6 "," $7 "," $8}'
done < $file
I am not able to replace the $2 with $mycol_new. Any suggestion?
awk
cannot see$mycol_new
because it is a shell variable. Here is one way of passing a shell variable into awk using the-v
flag:Here is an alternative method which lets the shell expand
$mycol_new
:why no one liners? Doing homework?
If you want to do this all in the shell, then you don't need awk: