I have 300 files in a folder. I have to append one new line at the end of all files in a folder.
How can i achieve it using grep.
I tried the following command but its not working
sed 's/$/\n/' /Path/filename.txt
Just say echo "" >> file . This will append a new line at the end of file .
Sometimes we need to work with a file for programming purposes, and the new line requires to add at the end of the file. This appending task can be done by using 'echo' and 'tee' commands. Using '>>' with 'echo' command appends a line to a file.
Append Text Using >> Operator Alternatively, you can use the printf command (do not forget to use \n character to add the next line). You can also use the cat command to concatenate text from one or more files and append it to another file.
The code works because sed by default appends a newline to its output if it is not already there. The code "$a\" just says "match the last line of the file, and add nothing to it." But implicitly, sed adds the newline to every line it processes (such as this $ line) if it is not already there.
Just say echo "" >> file
. This will append a new line at the end of file
.
To do it in all the files in the folder:
for file in *
do
echo "" >> "$file"
done
From the comments, in your case you have to say:
for file in /path/*.txt
do
echo "" >> "$file"
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With