-3

Hello I have the need to retrieve the sqlcode value from the outfiles that are generated after running sql statements.

The following value of the sqlcode below is obviously 0 and i would need to be able to grab that value from multiple blocks of statements formatted like below.

I cannot use GNU functions - grep/sed/awk may work but i havent been able to grab the sqlcode value using them myself...

Outfile will look like the following:

SQLCA Information

sqlcaid : SQLCA     sqlcabc: 136   sqlcode: 0   sqlerrml: 0

sqlerrmc:

 sqlerrp : SQLRI01F

sqlerrd : (1) -2147221503      (2) 1                (3) 4

           (4) 0                (5) 0                (6) 0

sqlwarn : (1)      (2)      (3)      (4)        (5)       (6)

           (7)      (8)      (9)      (10)       (11)

sqlstate: 00000
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
scocuzza
  • 21
  • 2
  • 6
  • 1
    Sounds like a homework question... [How do I ask homework questions on Stack Overflow](https://www.google.com/search?q=how+do+I+ask+homework+questions+on+Stack+Overflow). You are expected to make an effort. – jww Oct 28 '18 at 21:52
  • Please edit your Q to show your best attempt to solve the problem.(what you think should work); We can't help you improve your understanding if we don't know what you have tried. Good luck. – shellter Oct 28 '18 at 22:34

2 Answers2

1
sed -n '/sqlcode: /s/.*sqlcode: \([0-9]\+\) .*/\1/p'

If the line has the string "sqlcode: ", then substitute everything and remember one or more numbers after the string "sqlcode: " and before a space and print that remembered part.

Live version available at tutorialspoint.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • thanks for the answer..i see how this works but.... I wrapped the sed in a variable in a script var=$(sed -n '/sqlcode: /s/.*sqlcode: \([0-9]\+\) .*/\1/p' file.out) and when i implement this in a script on the linux AIX server with the file.out in the same directory it returns nothing...which i dont quite understand ive tried running it as shell and bash – scocuzza Oct 30 '18 at 00:25
0

awk '/sqlcode/ {print $7}' file

0

awk looks in the file for the default value / sqlcode /

print $ 7 prints the seventh field

noob
  • 9
  • 2