I am writing a shell script to pull apart words from text and process each word. I originally set out by having something like:
TEXT="This is some text. It has words, numbers (123.4), punctuation (!@#$$%), just stuff that people normally type."
for WORD in $TEXT; do
#Append results to buffer.
I noticed, though, I was only adding a single space between words when I was reassembling the output, and I really want to preserve the original whitespace.
My new thought was to have a loop like this:
1) Get any leading space.
2) Get any nonspace characters up to but not including a space.
3) result = Process(non-space)
4) append space+result to buffer
I am pretty sure I want to use sed to do parts 1 & 2, but I am having trouble getting myself in the proper mindset-- I can figure out how to replace pieces of the pattern space, but I am a little iffy on pulling out just the matches I want without the rest of $TEXT.
Does anybody have any pointers?