I have a file 20210823_Club_Member_Name_by_ID.txt. I want to get only the first element of the file name which is 20210823 and store it into a variable using shell script.
Currently, my code can print out the first element in the terminal but I also want to store it into a variable for further usage.
file='20210823_Club_Member_Name_by_ID.txt'
echo "$file" | awk -F'[_.]' '{print $1}'
// I try to store it like below, but it does not work
fileDate= echo "$file" | awk -F'[_.]' '{print $1}'
echo $fileDate