LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-19-2010, 04:51 AM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037

Rep: Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203

It's not something tricky like the file has been copied from a windows machine?

If you create a new file like:
Code:
jenhbvne

#kjeopb
rhiob
and then run the sed, does it leave only 2 lines?
 
Old 08-19-2010, 04:59 AM   #17
rgdacosta
Member
 
Registered: Jun 2007
Location: South Africa
Distribution: Linux Mint,Fedora, openSUSE, RHEL, SLES, Scientific Linux
Posts: 71

Original Poster
Rep: Reputation: 25
It does indeed change it!
 
Old 08-19-2010, 05:03 AM   #18
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Perhaps with grep also:
Code:
grep -v '^[[:blank:]]*\(\#.*\)\?$' file
Edit: I'm not sure if # needs to be escaped.

Last edited by konsolebox; 08-19-2010 at 05:04 AM.
 
Old 08-19-2010, 05:05 AM   #19
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

Has to be something typical to your distro/sed version

Just tested it on Debian Squeeze, Lenny and RHEL5.3 and works as expected.
Code:
sed -i '/^$/d' testfile
only removes the blank lines and leaves comment lines alone.

Very strange indeed!

Kind regards,

Eric
 
Old 08-19-2010, 06:31 AM   #20
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037

Rep: Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203
I am with Eric, I tried it in Ubuntu, Sourcemage, Slackware (live cd) and my own source distro and all have behaved the same with only removing blank lines
and leaving comments (using ^$ as regex)
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vim: How to hide commentary lines brianmcgee Programming 1 04-14-2008 09:15 AM
removing blank lines in a text file christianunix Linux - Newbie 11 10-29-2007 12:24 AM
Removing new lines from a file psandeepnair1985 Programming 5 03-25-2007 11:46 AM
How do i remove blank lines from a file? kakho Programming 1 04-15-2004 03:57 AM
Replace blank/almost blank lines in file Wynd Linux - General 3 01-27-2004 04:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration