Answer the question
In order to leave comments, you need to log in
How to add penultimate line to file via console?
Good day, please tell me how to add a line through the console with a command to the penultimate line, since the last line is closed with a bracket, and you can’t touch it.
param = {
some text,
some text,
some text,
some text,
some text,
add a line here
}
Answer the question
In order to leave comments, you need to log in
Delete last line
Append new line
Append parenthesis
1.txt
param = {
some text,
some text,
some text,
some text,
some text,
}
sed -i '$ d' 1.txt
echo 'новая строка' >> 1.txt
echo '}' >> 1.txt
cat 1.txt
param = {
some text,
some text,
some text,
some text,
some text,
newline
}
Isn't it easier without removing the last one (proposed by the posts above), adding text before the last $ line through the operand i - adds before.
sed -i '$i\text' myfile
so that is all...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question