Hi, I searched the forums but could not find anything that was very useful. I am trying to remove the very last line from a file and display the rest of the file.
Is there a way to use cut and tail together? Any other suggestions? Thanks
sed '$d' <input_filename >output_filename
Do you have to make an output file?
what do you want???
- to just display
$ sed '$d' your_infile_name
- to save the changes to a new file
$ sed '$d' <your_input_filename >new_output_filename
were the new_output_filename will be created once the command got executed. instead of your_input_filename provide your source filename and instead of output_filename just give some name. once after executed a new file will be created without the last line from your input_filename.
If you do not want to create extra file then you can do this :
echo "`sed '$d' file`" > file
I ran that command
sed '$d' OLD_FILE > NEW_FILE
and it just displays the OLD_FILE contents.
In other words I want to display everything up to the last line of the OLD_FILE but I don't know how many lines there are in the file, it changes everyday.
Check the number of lines in the files (wc -l).
that's ok,
can you check the old and the new files.
old file will contain all the lines.
new file will contain 1 line minus than the old.
So, your correct output will be in NEW_FILE.
Note: no issue with the no of line in the files.
That command doesn't work for me. It's pretty much just copying OLD_FILE to NEW_FILE. But it turned out I needed the last two lines because the last line of the file is blank.
I found this
sed 'N;$!P;$!D;$d' OLD_FILE > NEW_FILE
I very much appreciate the help.