LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-16-2010, 08:44 AM   #1
recomboDNA
LQ Newbie
 
Registered: Jun 2008
Distribution: Arch
Posts: 13

Rep: Reputation: 1
string editing: how to remove lines consisting of a single character?


I have a large text file that's formatted sort of like this:
Code:
foo bar
blah
Enormously Long String That Goes On and On and On and On and On
v
1234
1234 12 122 23 23 322ioogfs
$

yams are quite tasty, wouldn't you say?

.

why is there so much random garbage in this file?  Long story.
How do I remove the lines that consist of only a single character?
 
Old 07-16-2010, 08:49 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
In sed you can match lines containing any single character (dot) embedded in the begin of line (^) and end of line ($) anchors, e.g.
Code:
sed '/^.$/d' file
 
Old 07-16-2010, 08:55 AM   #3
recomboDNA
LQ Newbie
 
Registered: Jun 2008
Distribution: Arch
Posts: 13

Original Poster
Rep: Reputation: 1
Ahh, thanks. I was leaving out the '$', which was giving somewhat different results than I wanted.
 
  


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
[SOLVED] Using sed to remove lines around a specified string twchambers Linux - General 1 06-04-2010 11:19 AM
Remove last character from file/string linuxchump Programming 34 06-08-2009 04:01 AM
How do I remove lines that have more than one of a certain character in them? SentralOrigin Linux - General 2 01-14-2009 01:40 PM
minicom - send string or single ascii character neutron001 Linux - Software 1 04-10-2008 07:08 PM
remove the 'd' character from the end of string powah Programming 6 11-08-2007 07:00 AM


All times are GMT -5. The time now is 03:20 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