cannot delete certain files with sed
Is this a bug??
On certain files I can use this command correctly: sed 1d file1 However on other files (extracted from logs), I cannot remove the first line... sed 1d somefile seems to be performing nothing. This typical file, when viewed by vi, has a lot of "@" which disappear when i scroll downwards... What are these "@" ??? This file was extracted from a parsed logfile. I need to delete the first line of this file since an output of a "diff file1 file2" will pre-append some string which i don't need. thanks for your help, ganninu. |
sed 1d filename > newfile
will delete the first line of a text file. If the file has a binary format (some log files do) then it will not work the way you want. A binary file is one where the logical record is NOT delimited by a newline. Code:
wc -l filename |
so what do you suggest? :)
|
I do not know much about the file you are working with
What are you trying to do with the file? There are lots of ways to do things. |
The idea is this. I have a big growing logfile on a server. I'm grabbing the last 100 lines of this logfile and then I send it to a remote server. This remote server will have already a previous copy of this extracted file. Then I do a "diff" between these two versions. The problem is that 'diff -n file1 file2" returns me a reduntant line at the head of the file and i want to remove it. So, to cut it short, I'm using sed d1 file2 to remove the first line (generated by diff) of file2...
ganninu. |
You're using
Code:
tail -100 /somewhere/mylogfile > tmpfile For this file with garbage in it (using the filenames in the example I gave above) execute these commands (you can use vim or vi) vi tmpfile :set nu G You should now be at the last line of the file. Quote:
Plus, what does the garbage first line look like? |
erm... There is no garbage... everything is text... The first line i was talking abt was that one generated by DIFF - "d1 26" ... is there some special argument given to 'diff' to get rid of that???
...likewise, is there another fool-proof method to delete some lines out of a file? thanks, ganninu |
All times are GMT -5. The time now is 04:41 PM. |