user1614829
user1614829

Reputation: 31

save output of awk into a variable in a shell script

I need to save the output of this command into a variable

$scriptName | awk '{split($0,a,"_"); print a[1]}'

I tried to do this but it didn't work

schema=$( $scriptName | awk '{split($0,a,"_"); print a[1]}' )

can please someone tell me out to do that? thank you.

Upvotes: 1

Views: 7074

Answers (3)

Thor
Thor

Reputation: 47129

Third alternative:

$script | awk ' ... ' | read schema

Upvotes: 0

stark
stark

Reputation: 13189

Here's a slightly simpler way:

schema=`echo $scriptName |awk -F_ '{print $1}'`

Upvotes: 2

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143169

Try

schema="$( $scriptName | awk '{split($0,a,"_"); print a[1]}' )"

(with quotes). But how do you check if it works or not?

Upvotes: 0

Related Questions