LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 04-24-2010, 11:54 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,563

Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
Discard short lines?


Hello.

I have a file containing one word per line.
I want to discard all lines containing words shorter than five characters.

Have:
Once
upon
a
midnight
dreary
while
I
pondered
weak
and
weary

Want:
midnight
dreary
while
pondered
weary

Is there a Linux command which will do this?
I seek a basic command, not awk, not Perl, because I haven't learned those things yet.

Daniel B. Martin
 
Old 04-24-2010, 12:14 PM   #2
amani
Senior Member
 
Registered: Jul 2006
Location: Kolkata, India
Distribution: Debian 64-bit GNU/Linux, Kubuntu64, Fedora QA, Slackware,
Posts: 2,766

Rep: Reputation: Disabled
use regular expressions and any editing tool... what else?
 
Old 04-24-2010, 12:22 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
See my post in your other recent thread.....

Code:
egrep ".{5}.*" filename
Do you understand how this works? If not, go here: http://www.grymoire.com/Unix/Regular.html
 
Old 04-24-2010, 12:23 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
Code:
bash-3.1$ grep ..... test.txt
midnight
dreary
while
pondered
weary
I know I probably shouldn't have posted it, but it's so simple.
 
Old 04-24-2010, 11:10 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,515

Rep: Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892Reputation: 2892
Knowing how you are not ready for awk and such, here is asimple bash alternative:
Code:
#!/bin/bash

while read line
do
	[[ ${#line} -ge 5 ]] && echo $line
done <infile
 
Old 04-25-2010, 09:11 PM   #6
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,563

Original Poster
Rep: Reputation: 476Reputation: 476Reputation: 476Reputation: 476Reputation: 476
Quote:
Originally Posted by pixellany View Post
See my post in your other recent thread.....

Code:
egrep ".{5}.*" filename
Do you understand how this works? If not, go here: http://www.grymoire.com/Unix/Regular.html
Thanks for a perfect answer.
I'll mark this one as solved.

Daniel B. Martin
 
  


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
LXer: Samsung to Discard Windows Phone LXer Syndicated Linux News 0 11-10-2009 05:20 PM
LXer: This week at LWN: The trouble with discard LXer Syndicated Linux News 0 09-03-2009 12:11 AM
[SOLVED] [bash] sort string and discard duplicates hashbang#! Programming 10 08-21-2009 06:17 AM
Random packet discard usman_minhas Programming 2 05-12-2009 02:07 AM
How to discard mail by any user in sendmail er_gaurav22 Linux - Server 2 11-09-2007 05:04 AM

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

All times are GMT -5. The time now is 09:28 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration