0

I has many file need to add a $var in txt file , I don't know how to do

#get file name

filename=`find . -not -name '*Err*' -name *202210*.txt`

#get file date

filedate=`find . -not -name '*Err*' -name *202210* | awk -F _ '{print $2,$3}' | awk -F . '{print $1}'

#add file date in txt file

for i in $filedate
do
    sed "s/^/$filedate /" $filename
done

but I got a error message "bad option in substitution expression"

and I try to see this quest, but I don't know how to fix this problem. Using different delimiters in sed commands and range addresses

  • Probably also review https://mywiki.wooledge.org/BashFAQ/020 and [When to wrap quotes around a shell variable](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable). Generally, try https://shellcheck.net/ before asking for human assistance. – tripleee Nov 01 '22 at 08:44
  • It's not clear what your Awk commands should do but they can almost certainly be combined into a single script. – tripleee Nov 01 '22 at 08:45

0 Answers0