I need script to convert this holiday list into date format. My input file
MMYYYY CAL_B2K_ID 123456789012345678901234567890
------ ------------ -------------------------------
012016 821 YY Y Y Y Y
012016 DC YY Y Y Y Y
022016 DC Y Y Y Y
022016 821 Y Y Y Y
032016 DC Y Y Y Y
032016 821 Y Y Y Y
042016 821 Y Y Y Y
Now 123456789012345678901234567890 is like date when first time 0 comes it is 10 and then 1 means 11 and this is so on. ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14............
So I have created script where ever Y is present it convert into date suppose in first line Y is present under 1, 2,9,6,3,9
In my script i have cut each line from column 21- 52 and checking if that column is Y, if yes then it covert into date like if Y is present under column number 23. Then I am subratcing (coloumn number - 20) it will give me 3 And then i am using concat operatior to make date.
Below is my script. But i am facing issue when there is no Y under any coloumn it takes my var as blank and blank is also coming under true condition .
var=echo $f1 | cut -c$i
if [[ "$var"='Y' ]] ;
And my script is below.
rm f1.txt
set -x
while read f1
do
for((i=21;i<23;i++));
do
var=`echo $f1 | cut -c$i`
if [[ "$var"='Y' ]] ;
then
echo $var
month=`echo $f1 | cut -c1-2`
year=`echo $f1 |cut -c3-6`
date=$(($i-20))
echo $year"-"$month"-"$date >> f1.txt
fi
done
done < holiday_india.txt`
Please let me know what I will do so that when there is nothing in var , it will not come under If condition true.
O/p of this script is that it convert all coloumn of each line from 21-52 into date not where Y is present.
Hope I clarify now.
Y
to something, or what? – ilkkachu Sep 26 '16 at 8:49