Reputation: 71
Input file:
2012/01/18 11:24 GMT+00:00 adm Add "/david/admin" "/apps/data/unix/archives/osn/admin" ""
I did
awk -F'"' print {$2"}' /file/path
and I got
/david/admin
and
awk -F'"' print {$4"}
got me
/apps/data/unix/archives/osn/admin
Is there to combine these and store them in individual variable?
Example:
name=/david/admin
path=/apps/data/unix/archives/osn/admin
Upvotes: 2
Views: 144
Reputation: 41446
You have lots of typo in your awk, as written above, they does not give what you tell they are giving.
Wrong awk -F'"' print {$4"}
correct awk -F'"' '{print $4}'
.
Here is how I would store to shell variable.
name=$(awk -F\" '{print $2}' file)
path=$(awk -F\" '{print $4}' file)
Upvotes: 0
Reputation: 77079
If you want to store them in awk variables, you're basically done:
$ awk -F'"' '{ name=$2;path=$4 } { print name }' <<< '2012/01/18 11:24 GMT+00:00 adm Add "/david/admin" "/apps/data/unix/archives/osn/admin" ""'
/david/admin
If you want to store them in shell variables, use read
instead of awk.
$ IFS='"' read _ name _ path _ <<< '2012/01/18 11:24 GMT+00:00 adm Add "/david/admin" "/apps
/data/unix/archives/osn/admin" ""'
$ echo $name
/david/admin
$ echo $path
/apps/data/unix/archives/osn/admin
Upvotes: 4