LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-24-2009, 12:14 PM   #1
Dazamondo
LQ Newbie
 
Registered: Jun 2009
Posts: 7

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


Hi

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.

Cheers
Daz
 
Old 07-24-2009, 01:19 PM   #2
zQUEz
Member
 
Registered: Jun 2007
Distribution: Fedora, RHEL, Centos
Posts: 294

Rep: Reputation: 54
this might work for what you want: `cat file.in |sed 's/ .\{1,5\} //g' >file.out`
 
Old 07-24-2009, 02:14 PM   #3
Dazamondo
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, 03:28 PM   #4
ncsuapex
Member
 
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 03:31 PM. Reason: .
 
  


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


All times are GMT -5. The time now is 10:07 AM.

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