Skip to main content
Edit on @Ed Morton suggestion comment.
Source Link
{ pad = s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; reverse =~ //; print "$_ : $s - $+[0]" ' sample 
{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; reverse =~ //; print "$_ : $s - $+[0]" ' sample 
{ pad = s = match($0, /[A-Z]/); clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; reverse =~ //; print "$_ : $s - $+[0]" ' sample 
deleted 7 characters in body
Source Link
{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; scalar reverse =~ //; print "$_ : $s - $+[0]" ' sample 
{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; scalar reverse =~ //; print "$_ : $s - $+[0]" ' sample 
{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; reverse =~ //; print "$_ : $s - $+[0]" ' sample 
added 148 characters in body
Source Link
{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; scalar reverse =~ //; print "$_ : $s - $+[0]" ' sample 
{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile

{ s = match($0, /[A-Z]/); pad = RSTART clone = substr($0, RSTART + 1) while (match(clone, /[A-Z]/)) { clone = substr(clone, RSTART + 1) pad += RSTART } print $0, ": ", s, length - --pad } 

Save in a file (Eg.: find_index.awk) with #!/bin/awk -f as the first line (shebang) and run as ./find_index.awk yourfile


If perl is fine :

perl -lne ' /[A-Z]/; $s = $+[0]; scalar reverse =~ //; print "$_ : $s - $+[0]" ' sample 
Source Link
Loading