LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command to delete words less than 5 characters? (https://www.linuxquestions.org/questions/linux-newbie-8/command-to-delete-words-less-than-5-characters-742502/)

Dazamondo 07-24-2009 11:14 AM

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

zQUEz 07-24-2009 12:19 PM

this might work for what you want: `cat file.in |sed 's/ .\{1,5\} //g' >file.out`

Dazamondo 07-24-2009 01:14 PM

No that is one of the commands I have tried myself but the file that is created is empty.

ncsuapex 07-24-2009 02:28 PM

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.


All times are GMT -5. The time now is 04:56 AM.