I would like to process the text file (test.txt) using the Linux command as follows.
before processing:
--SQL
After processing:
header
-- SQL
footer
The following shell scripts did not work:
I would appreciate it if you could tell me how it works.
test.sh
#not found.
sed-i'1s/^/header\\n/'test.txt
# For some reason, the file name test.txt· is created.
echo footer>>test.txt
$sed-i-E-e'1 iheader'-e'$afooter'test.txt
$ cat test.txt
header
-- SQL
footer
Another example of not using sed
.
#!/bin/sh
echo "header" > > result.txt
cat test.txt>>result.txt
echo "footer" > > result.txt
There is no big mistake in the code of the question.This code does not cause "not found" or "test.txt·" to be created.I guess I did something wrong when I was trying a lot of things.
A small mistake is \\n
.\n
is correct.(\n
seems to be a GNU extension, but the -i
option is a GNU extension in the first place, so I think it's a usable environment.)
© 2024 OneMinuteCode. All rights reserved.