how to pass container id to docker exec through output of another cmd

i want to pass docker container id from output of another linux command

example :
save output of docker ps cmd to a file
docker ps > docker.log
grep only container id : awk ‘FNR == 2{print $1}’

now i want to pass the output of awk cmd to docker exec

like docker exec -it awk ‘FNR == 2{print $1}’ /bin/bash (i am not able to pass container id through cmd)

this is to automate a process that needs ssh in docker containers

Source: StackOverflow