UNIX shell script question

I am writing the following command in the shell script:
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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

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`
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

    var1=`/home/user1/Python/bin/bq --format prettyjson show mytab1 | awk '/lastModifiedTime/{print substr($0,21,10)}'
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.