I have used an awk command to find a particular line in a file and would like to prepend this in a second file. Can someone help me in this respect?
1s;^;to be prepended; substitutes the beginning of the first line by the given replacement string, using ; as a command delimiter.
Add Text to Beginning of File Using echo and cat Commands Then, we simply output the variable and redirect it to the same file. As you can see above, the new text was added on a new line at the beginning of the file. To add the text at the beginning of the existing first line, use the -n argument of echo.
Append to a File using the Redirection Operator ( >> ) The >> redirection operator appends the output to a given file. There are a number of commands that you can use to print text to the standard output and redirect it to the file, with echo and printf being the most used ones.
The short answer is that you can't. You'll need a temp file.
echo "Prepended Line" > tmpfile && cat origfile >> tmpfile && mv tmpfile origfile
Edit:
sed -i 's/\(line you want\)/Prefix \1/g' origfile
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