0

What I am trying to do is to scan a text file word by word and find all words of 4 character or less then output these words to a file, but the problem is I don't know a unix command that can scan the file this way. The Grep command only enable me to find a certain word in a file. Any help is appreciated

2
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by jim mcnamara
0

try awk. This is a start:

awk '{ 
       for(i=1;i<=NF;i++) 
       {
         if(length($i)<5) 
         {print $i}
       }
       }'  filename  > newfilename

Thank you.

Taking this step further. How can I filter out these 4 or less characters words, so that the newfilename only contain palindromes words?

0

We are now clearly doing homework.

This is the limit of help->
1. redirect the output of the awk script into a loop instead of into a file.

for word in `awk script above`
do

done

the part between do ... done is now yours.
read the man page for rev, and learn how to compare two strings in an if statement.
use one string for the original version of the $word variable, and reverse another.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.