We help IT Professionals succeed at work.

UNIX shell script question

toooki
toooki asked
on
525 Views
Last Modified: 2014-08-07
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.
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Nem SchlechtIT Supervisor
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
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`
Nem SchlechtIT Supervisor
CERTIFIED EXPERT
Top Expert 2009

Commented:
Yup, off by one error on my part.

Author

Commented:
Worked perfectly.
Thanks a lot.
CERTIFIED EXPERT

Commented:
grep then cut?  How about:

    var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | awk '/lastModifiedTime/{print substr($0,21,10)}'
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.