Im trying to understand sed command and loops.
I need to take part of the text (20 lines) and append it to the csv with the file name.
here is my code
for i in ~/mspl/*.doc
do
catdoc "$i" > auto.txt
sed -e '1,20!d' auto.txt > auto1.txt
sed -e '1s/^/"$i" ;/' auto1.txt > auto2.txt
sed -e '20s/$/~/' auto2.txt > auto3.txt
cat auto3.txt >> lines.csv
done
the problem is that my second “i” argument doesn’t convert to the file name in csv.
in the line
sed -e '1s/^/"$i" ;/' auto1.txt > auto2.txt
Please tell what is my mistake here?
The issue is that variables are not expanded within single quotes
'. Use double quotes instead":If your double-quoted string needs to contain explicit double quotes, you have to escape them (
\"). If using double quotes is not an option (e.g. if you have a very complex command with multiple levels of quoting already) you can always exit the quoting around your variable: