I have a long text file, with some sections defined by these brackets on separate lines:
[EnvVarDefns]
[EnvVarDefns]
[PROJECT]
[EnvVarValues]
These lines occur only once, except for [EnvVarDefns] in the document, and it should be rather simple to select the text between them.
I want to save everything between the 2nd [EnvVarDefns] and [PROJECT] lines to one file, and finally everything from [EnvVarValues] to end of file to another file. After the selection, I do some data cleaning which I have verified works as intended. Only the first selection part is not working currently. I have this code:
for project in $projectlist
do
sed -n 's/[EnvVarDefns]\(.*\)[PROJECT]/' file | sed /s/^/$project';'/ | sed 's/\\/;/g' | sed 's/;//9g' >> /params.csv;
sed -n 's/^[EnvVarValues]/p' file | sed /s/^/$project';'/ | sed 's/\\/;/g' | sed 's/"//g' >> /values.csv;
done
This gives me the following errors:
sed: -e expression #1, char 31: unterminated `s' command
sed: -e expression #1, char 4: unknown command: `^'
sed: -e expression #1, char 19: unterminated `s' command
Any idea what is causing this?
UPDATE:
New code using awk:
for project in $projectlist
do
awk '/\[EnvVarDefns]/ { found++ } found > 1 && printed <= 2 { print; printed++ }/{flag=1;next}/\[PROJECT]/{flag=0}flag' FILE |
sed /s/^/$project';'/ | sed 's/\\/;/g' | sed 's/;//9g' >> /filepath/file1.csv;
sed '1,/\[EnvVarValues]' FILE | sed /s/^/$project';'/ | sed 's/\\/;/g' | sed 's/"//g' >> /filepath/file2.csv;
done