Taking out part of a string by matching a pattern

Hi All,

My Problem is like below.

I have a file which contains just one row and contains data like

PO_CREATE12457888888888889SK1234567878744551111111111SK89456321145789955455555SK8888888815788852222

i want to extract SK12345678

SK89456321
SK88888888

So basically SK and next 8 characters.
can someone please help.

I am not quite sure what the desired output is given your sample input.
What does this mean?

 i want to extract SK12345678

Furthermore, indicate your OS and shell type.

---------- Post updated at 12:03 PM ---------- Previous update was at 11:18 AM ----------

if you have gawk available:

echo 'PO_CREATE12457888888888889SK1234567878744551111111111SK89456321145789955455555SK8888888815788852222' | gawk -v FPAT='SK[0-9]{8}' 'NF{for(i=1;i<=NF;i++) print $i}'
SK12345678
SK89456321
SK88888888
$ 
$ echo PO_CREATE12457888888888889SK1234567878744551111111111SK89456321145789955455555SK8888888815788852222 | perl -lne 'while (/(SK.{8})/g){print $1}'
SK12345678
SK89456321
SK88888888
$ 
$ 

You could also use the -o option to egrep

$  echo PO_CREATE12457888888888889SK1234567878744551111111111SK89456321145789955455555SK8888888815788852222 | egrep -o "SK.{8}"
SK12345678
SK89456321
SK88888888
1 Like

Does

sed 's/SK........//g' inputfile >outputfile

work?