I have this bash script#!/bin/bashcat $@ | while read linedo    for word in $line    do        echo $word | circling-the-square        # here's where i need to add the if statement:        #if the word contains one of the four [!?.,],        #then also echo that punctuation mark    donedonecircling-the-square is a Python script based on Norvig's spelling corrector.That script rids its input of punctuationdef words(text): return re.findall('[a-z]+', text.lower()) so I need bash to notice this. I guess sed or awk might be useful but I still don't know how to write that regex or put it in an if statement, so I'm asking this here.As is, passing the filealec@ROOROO:~/oddi-o/newton-fluxions$ cat 199 advertisement lately publijtid by the author, the british hemisphere, or a map of a new contrivance, proper for initiating young minds in the firft rudiments of geography, and the ufe of the globes.givesalec@ROOROO:~/oddi-o/newton-fluxions$ ./hmmb 199advertisementlatelypublijtidbytheauthorthebritishhemisphereoramapofanewcontrivanceproperforinitiatingyoungmindsinthefirstrudimentsofgeographyandthefewoftheglobes.Which isn't perfect but still useful. FYI, I have edited the file in question to contain only \w and the punctuation [!?.,]. The file does not contain characters like : or ;, so I just need it to echo these four punctuation marks if they are included as part of a word, viz.:alec@ROOROO:~/oddi-o/newton-fluxions/finforno$ ./hmmb 199advertisementlatelypublijtidbytheauthor,thebritishhemisphere,oramapofanewcontrivance,properforinitiatingyoungmindsinthefirftrudimentsofgeography,andtheufeoftheglobes.
How do I add an if statement (regarding punctuation in a word) to this bash script
bash;shell script;sed;awk
Use a regex as shown below. It finds words containing one or more of your specified punctuation marks and prints out the word and the first matching punctuation mark. You can extend it as you see fit.if [[ $word =~ ^.*([!?.,])+.*$ ]]then    echo Found word: $word containing punctuation mark: ${BASH_REMATCH[1]}fi