Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 07-24-2009, 11:14 AM   #1
LQ Newbie
Registered: Jun 2009
Posts: 7

Rep: Reputation: 0
Command to delete words less than 5 characters?


I am trying to remove words from a text file that are less than 5 characters. I have tried grep and sed but don't seem to be removing every occurrence that is less than 5 characters long.

I probably doing something stupid but any help would be greatly appreciated.

Old 07-24-2009, 12:19 PM   #2
Registered: Jun 2007
Distribution: Fedora, RHEL, Centos
Posts: 294

Rep: Reputation: 54
this might work for what you want: `cat |sed 's/ .\{1,5\} //g' >file.out`
Old 07-24-2009, 01:14 PM   #3
LQ Newbie
Registered: Jun 2009
Posts: 7

Original Poster
Rep: Reputation: 0
No that is one of the commands I have tried myself but the file that is created is empty.
Old 07-24-2009, 02:28 PM   #4
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 43
try this

sed -ni '/^.\{5\}/!p' filename

do it without the i first that will print the results on the screen but will not change the file. The i will do the sed command inline, which means it will do the command and edit the filename without creating a new file.

EDIT: Oops this only deletes lines that are 5 characters or less.

Last edited by ncsuapex; 07-24-2009 at 02:31 PM. Reason: .


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
Command to delete words out of a text file. Dazamondo Linux - Newbie 13 06-30-2009 10:48 AM
grepping 'how many words have x number of characters' dtat651 Linux - Newbie 17 07-27-2008 11:24 PM
How do I extract characters from several words on a line? MheAd Linux - Newbie 22 06-23-2008 10:22 PM
delete words in vi & autologin? hraposo Slackware 6 10-02-2004 10:12 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:40 PM.

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