I
I
Igor Petrov2020-11-11 21:09:56
linux
Igor Petrov, 2020-11-11 21:09:56

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

3 answer(s)
V
Vladimir Kuts, 2020-11-11
@daniks

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
}

V
Valdemar Smorman, 2020-11-11
@smorman

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...

K
ky0, 2020-11-11
@ky0

Delete the last line, append to the end of the file, add a parenthesis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question