-3

Modifying the query to provide some more context.

I am writing a groovy script to get a list of objects output s3://xyz/1/abc s3://xyz/2/lmo s3://xyz/6/hjl

I need to grep the largest number in middle (here 6).

On command line I tried echo "xyz/23/xyz/jhdids/dsd"|awk -F\/ '$0=$2' awk: warning: escape sequence \/' treated as plain/' 23;

It works on command prompt. But when I try to embed it in my groovy script, it gives error. In groovy - $4 has the value xyz/23/xyz/jhdids/dsd

aws s3 ls --recursive s3://xyz | sort | tail -n 1 | awk '{print $4|awk -F\/ '$0=$2'}\'

Hope this elaborates my issue. Thank you

bhakti
  • 61
  • 5
  • Welcome to Stack Overflow! Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to *specific* programming problems -- but we will happily help you write it yourself! Tell us [what you've tried](http://stackoverflow.com/help/how-to-ask), and where you are stuck. This will also help us answer your question better. – Thomas Ayoub Mar 16 '17 at 15:20
  • Possible duplicate of [shell script. how to extract string using regular expressions](http://stackoverflow.com/questions/19737675/shell-script-how-to-extract-string-using-regular-expressions) – Andria Mar 16 '17 at 15:21

1 Answers1

0
<linux_command> | grep -oP "\/\K(\d+)(?=\/.*)"
ded
  • 150
  • 1
  • 11