Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

UNIX shell script question

I am writing the following command in the shell script:
#!/bin/bash
var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | grep "lastModifiedTime"`

The above returns:
  "lastModifiedTime": "1407393977076",

If I write:
var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | grep "lastModifiedTime" | awk -F"\"" '{print $4}'`
The above returns 1407393977076

I only need the first 10 digits of the above number which is 1407393977
Could you please help me update the above command so that the above returns 1407393977 (not 1407393977076) ?
I need to preferably use a single command.
Thank you.
0
toooki
Asked:
toooki
2 Solutions
 
serialbandCommented:
try this

var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | grep "lastModifiedTime" | awk -F"\"" '{print $4}'`|cut -c 1-10

Open in new window

0
 
nemws1Database AdministratorCommented:
Since you're going to have pretty static output, you can skip the awk and go right to the cut:
var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | grep "lastModifiedTime" | cut -c 22-32`

Open in new window

0
 
tel2Commented:
Well said, nemws1, except 22-32 is 11 chars, and we want 10.

Should be this:
    var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | grep "lastModifiedTime" | cut -c22-31`
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
nemws1Database AdministratorCommented:
Yup, off by one error on my part.
0
 
toookiAuthor Commented:
Worked perfectly.
Thanks a lot.
0
 
simon3270Commented:
grep then cut?  How about:

    var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | awk '/lastModifiedTime/{print substr($0,21,10)}'
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now