Get days using awk

hi
i want to get days using awk command
[source data]

kkk bb 20191210 ccc ddd
kkk bb 20191211 ccc ddd

[output data]

kkk bb 20191210 Tue ccc ddd
kkk bb 20191211 Wed ccc ddd

please help me

--- Post updated at 06:19 AM ---

in addition,
i want to get the day of the week using the third column value.of source data

Hello tomato00,

On UNIX.com we encourage users to add their efforts whatever they have put in order to solve their own problems.
So kindly do let us know your efforts.

Thanks,
R. Singh

1 Like

i tried do follow, but i can't print => aaa 20191212 Thu

#>echo "aaa 20191212" | awk '{system("echo $(date -d "$2" +'%a')") }'
Thu

Hello tomato00,

Could you please try following.

cat script.ksh
declare -a arr=("test" "Monday" "Tuesday" "Wednesday" "Thurday" "Friday" "Saturday" "Sunday")

while read first second date_part rest_part
do
   echo "$first $second $date_part ${arr[$(date -d "$date_part" +%u)]} $rest_part"
done < "Input_file"

Thanks,
R. Singh

2 Likes

hi RavinderSingh13
wonderful, my problem solved.
Thank you so much.