Please provide a command to append an existing file by taking a last line of another file.
You can use grep to search for a regular expression in details. txt and redirect the result to the new file. If not you will have to search for each line you want to copy, still using grep, and append them to new. txt using >> in stead of > .
tail [OPTION]... [ Tail is a command which prints the last few number of lines (10 lines by default) of a certain file, then terminates. Example 1: By default “tail” prints the last 10 lines of a file, then exits.
To copy a line requires two commands: yy or Y ("yank") and either p ("put below") or P ("put above"). Note that Y does the same thing as yy .
To copy files and directories use the cp command under a Linux, UNIX-like, and BSD like operating systems. cp is the command entered in a Unix and Linux shell to copy a file from one place to another, possibly on a different filesystem.
tail -n 1 $file1 >> $file2
Though most systems also support
tail -1 $file1 >> $file2
tail $file1 -n 1 >> $file2
Or,
tail -1 $file1 >> $file2
If you want it to work with sudo
:
tail -1 $file1 | tee -a $file2
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