Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, July 16, 2016

Bash - Printing out sentences line by line

Bash - Printing out sentences line by line


I have yet another bash question. If I have a file like...

Today is sunny. I like the sun. It is awesome!  

And I want to print out each char until it hits a ?, ., or !. can this also be a awk one liner? I want the printout to look like.

Today is sunny.  I like the sun.  It is awesome!  

Answer by SzG for Bash - Printing out sentences line by line


echo Today is sunny. I like the sun. It is awesome! | sed 's/[.!?] */&\n/g'  

Answer by Karoly Horvath for Bash - Printing out sentences line by line


You just have to specify the record separator:

awk 'BEGIN {RS="[.!?] *"} {print}'  

Answer by klashxx for Bash - Printing out sentences line by line


Something close in awk (not exactly want needed but interesting):

echo 'Today is sunny. I like the sun. It is awesome!'|awk '1' RS='[.,?]'  

The canonical awk way:

echo 'Today is sunny. I like the sun. It is awesome!'|gawk 'a=gensub(/(\.|!|\?) */, "\\1\n", "g"){print a}'  

Answer by Taher Khorshidi for Bash - Printing out sentences line by line


a solution using sed:

sed 's/\([\?\!\.]\)\s*/\1\n/g'  

Answer by aedunn for Bash - Printing out sentences line by line


echo Today is sunny. I like the sun. It is awesome! | awk '{gsub(/([?,.!])/,"&\n");print}'  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.