How to extract next n characters after a match is found?

Hi,

I want to extract the next 7 characters after I encounter the first ( in the code

eg

abc123=(xvn1342)
xyz678123=(ret8901)

I want to extract xvn1342,ret8901.

Please advise how to achieve this with awk, if possible?

echo 'abc123=(xvn1342)' | awk -F"[()]" '{print $2}'
  awk -F[\(\)=] '{print substr($3,1,7) }'  infile

If ALL of the values inside the () are seven characters long then

  awk -F[\(\)=] '{print $3 }'  infile

i tried this, but it gave blank output

Using awk match function:-

awk '{match($0,/\(/);print substr($0,RSTART+1,7)}' file

Not working. Mine is a Solaris version

It doesn't work on Linux either.

Try this:

awk -F"(" '$2 { print substr($2,1,7) }' inputfile
1 Like
bash-3.2$ awk -F"(" '$2  { print substr($2,1,7) }' inputfile
awk: syntax error near line 1
awk: bailing out near line 1

as the saying goes: use nawk instead of awk on Solaris...........

1 Like

ahhhh....worked like a charm. Thanks

---------- Post updated at 06:24 PM ---------- Previous update was at 06:23 PM ----------

used nawk as suggested below.. It worked..thanks for the above though