2

I am trying to strip everything except letters and delete any letters that is less than 3 characters in my bash script... I got it to delete words that has 3 characters, but other rules are not applied. Here's what I'm using:

name="The Man From U.N.C.L.E. Official 2 2015 Henry Cavill Armie Hammer Spy Movie AS HD"
keyword="$(sed -e 's/ [a-zA-Z]\{3\} / /g' <<< "$name")"

Desired output is

echo $keyword

shows

The Man From Official Henry Cavill Armie Hammer Spy Movie

any kind of help I can get on this is greatly appreciated!

1 Answer 1

2

Try this with GNU sed:

name="The Man From U.N.C.L.E. Official 2 2015 Henry Cavill Armie Hammer Spy Movie AS HD"
keyword="$(sed -E 's/\b(.{1,2}|[0-9]+)\b/ /g;s/ +/ /g' <<< $name)"
echo "${keyword% }"

Output:

The Man From Official Henry Cavill Armie Hammer Spy Movie
1
  • code above but it leaves whitespaces... how can we get rid of numbers...2015 and just keep all words longer than 3 characters?
    – thevoipman
    Commented Jun 13, 2015 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.