LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-10-2003, 09:56 AM   #1
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Rep: Reputation: 30
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.
 
Old 12-10-2003, 11:37 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
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
will give you the number of newlines in the file. However, binary files can have ANY character embedded in the logical record, even newlines -- which are ignored.
 
Old 12-10-2003, 11:53 AM   #3
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Original Poster
Rep: Reputation: 30
so what do you suggest?
 
Old 12-10-2003, 12:00 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
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.
 
Old 12-10-2003, 12:12 PM   #5
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Original Poster
Rep: Reputation: 30
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.
 
Old 12-10-2003, 02:19 PM   #6
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
You're using
Code:
 tail -100 /somewhere/mylogfile > tmpfile
and the first line of tmpfile always has a bunch of garbage in it?

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:
100 bsauve 7126 1 0 Nov 17 ? 7:49 uzposs2
You should see a 100 over in the left column - meaning your file has 100 lines. What do you see? Do you see 100?

Plus, what does the garbage first line look like?
 
Old 12-10-2003, 04:31 PM   #7
ganninu
Member
 
Registered: Jul 2003
Distribution: RH 7.3/8.0/9.0, Debian Stable 3.0, FreeBSD 5.2, Solaris 8/9/10,HP-UX
Posts: 340

Original Poster
Rep: Reputation: 30
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

Last edited by ganninu; 12-10-2003 at 05:39 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete text between key words : sed shalomajay Programming 7 05-11-2011 07:22 PM
[SOLVED] delete the end of each line in a file with sed angel115 Linux - Newbie 3 11-16-2005 05:41 PM
how to delete duplicates entries in xml file using sed/awk/sort ? catzilla Linux - Software 1 10-28-2005 03:57 PM
trying to delete a line with sed deoren Linux - General 2 01-03-2005 10:26 PM
delete line specified by variable wihin shel script with sed lnchatterbox Linux - Newbie 2 02-23-2004 02:24 PM


All times are GMT -5. The time now is 11:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration