I'm trying to get the character that precede each occurrence of given character/pattern in a string using standard bash tools as grep, awk/gawk, sed ...
Step I
: get the character that precede each occurrence of the character :
Example:
String 1 => :hd:fg:kl:
String 2 => :df:lkjh:
String 3 => :glki:l:s:d:
Expected results
Result 1 => dgl
Result 2 => fh
Result 3 => ilsd
I tried many times with awk but without success
Step II
: Insert a given character between each character of the resulting string
Example with /
Result 1 => d/g/l
Result 2 => f/h
Result 3 => i/l/s/d
I have an awk expression for this step awk -F '' -v OFS="/" '{$1=$1;print}'
I don't know if it is possible to do Step I
with awk or sed and why not do Step I
and Step II
in once.
Kind Regards
o
oro:
or something else? If it cannot happen then add a statement to your question saying so.