I want to find all sequences that are in alphabetical order in txt file. not sorting.in text file have-aedftgwqofabcdefoufnpqrsaabcdI want output - abcdef and pqrsalso without repeating characters like 'aabcd'
find sequences that are in alphabetical order
linux;text processing;grep
With perl$ cat ip.txt aedftgaabcdwqofabcdefoufnpqrs   $ perl -F -lane '$m=1; foreach (1..$#F){ $m=0 && last if $F[$_] le $F[$_-1] } print if $m' ip.txtabcdefpqrsInput line is split character wise into @F arrayIf any character occurs alphabetically prior (or same character) to the character before it, the match variable $m is set to 0 and loop is quit immediatelyNote this solution is partially case-sensitive, Pqrs will match but pQrs will failIf pqrs is changed to pQrs and still needs to be matched:$ perl -lne '(@s) = split//,tr/A-Z/a-z/r; $m=1; foreach (1..$#s){ $m=0 && last if $s[$_] le $s[$_-1] } print if $m' ip.txt abcdefpQrs