given the name of a file as an argument,the script reads the file name and creates a new file containing only lines which consist of one word.
An example input and output will be
There are 20 students in the class. [TAB][SPACE] Nearly half of them are enrolled in FoS. The rest are in Faculty-Of-ES.
The output from the script should look like
There [TAB][SPACE] Nearly Faculty-Of-ES.
Hello I am a beginner programmer and I am trying to learn bash scripting for over a month now but questions like this still stump me.
Please outline the general approach .Thank you
grep -P "^[\s]*[0-9A-Za-z-]+.?[\s]*$" test.txtWhere
test.txtcontains the input text.Here I am defining a word as having zero or more whitespace in the beginning and end . Then any combination of alphabets, digits and
-and optionally ending with a period.NOTE :: This will not work if you are considering floating point numbers as a word. Hence your definition of a
worddefines the result and the regex.