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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-10-2003, 08:56 AM
|
#1
|
|
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:
|
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.
|
|
|
|
12-10-2003, 10:37 AM
|
#2
|
|
Member
Registered: May 2002
Posts: 964
Rep:
|
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.
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.
|
|
|
|
12-10-2003, 10:53 AM
|
#3
|
|
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:
|
so what do you suggest? 
|
|
|
|
12-10-2003, 11:00 AM
|
#4
|
|
Member
Registered: May 2002
Posts: 964
Rep:
|
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.
|
|
|
|
12-10-2003, 11:12 AM
|
#5
|
|
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:
|
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.
|
|
|
|
12-10-2003, 01:19 PM
|
#6
|
|
Member
Registered: May 2002
Posts: 964
Rep:
|
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?
|
|
|
|
12-10-2003, 03:31 PM
|
#7
|
|
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:
|
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 04:39 PM.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:43 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|