I have this line in my Linux shell script
sed '$a\' < file_a.txt
Afraid to remove it from the code and cannot find out what it is for.
It means that sed will read the next line and start processing it. nothing will be printed other than the blank lines, three times each. Show activity on this post. The command d is only applied to empty lines here: '/^$/d;p;p'.
The SED command in Linux stands for Stream EDitor and is helpful for a myriad of frequently needed operations in text files and streams. Sed helps in operations like selecting the text, substituting text, modifying an original file, adding lines to text, or deleting lines from the text.
Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening them, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. SED is a powerful text stream editor.
To use sed, you write a script that contains a series of editing actions and then you run the script on an input file. Sed allows you to take what would be a hands-on procedure in an editor such as vi and transform it into a look-no-hands procedure that is executed from a script.
It makes sure the output will end with a newline; see:
echo -ne test | sed '$a\'
# same output as:
echo test | sed '$a\'
As you can see with the previous code, a carriage return isn't added in the second example but one is added in the first example. Of course, if you remove the sed
part, the output will be different since the first echo
statement has no carriage return.
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