I want to delete first and last line from the file
file1 code :
H|ACCT|XEC|1|TEMP|20130215035845|
849002|48|1208004|1
849007|28|1208004|1
T|2
After delete the output should be
849002|48|1208004|1
849007|28|1208004|1
I have tried below method but has to run it 2 times, I want one liner solution to remove both in one go!
sed '1,1d' file1.txt >> file1.out
sed '$d' file1.out >> file2
Please suggest one liner code....
sed -i '$ d' filename . The -i flag edits file in place. This deletes the last line. To delete the first line, use sed -i '1,1d' filename .
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
There is no available to delete all contents of the file. How to delete all contents of the file using sed command.
It is a sed command. d is the command for deleting a line, while $ means "the last line in the file". When specifying a location (called "range" in sed lingo) before a command, that command is only applied to the specified location. So, this command explicitly says "in the range of the last line in a file, delete it".
You could use ;
sed '1d; $d' file
In sed, you can separate commands using a semicolon. For example:
sed '1d; $d' /path/to/file
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