The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to modify a file using shell script syamkp Shell Programming and Scripting 1 03-07-2008 09:16 AM
variables in shell viko Shell Programming and Scripting 2 03-03-2008 08:09 PM
How to modify an existing pdf with unix shell commands fandwick UNIX for Advanced & Expert Users 3 06-08-2007 07:28 AM
Using shell variables In awk nortypig Shell Programming and Scripting 11 08-23-2006 09:48 PM
Is it possible in a shell script to modify itself ?? sehgalniraj Shell Programming and Scripting 5 03-22-2005 09:21 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-26-2007
Registered User
 

Join Date: Jan 2006
Posts: 23
Modify shell variables with AWK

Dear Folks,

I have a command output something like:

Quote:
# gsmctl -d /dev/ttyS0 pin sig
<PIN0> READY
<SIG0> 31
And I want to store PIN0 and SIG0 in two shell variables, now I do a double awk:

Code:
PIN=`gsmctl -d /dev/ttyS0 pin sig | awk '/PIN0/ { print $2}'` 
SIG=`gsmctl -d /dev/ttyS0 pin sig | awk '/SIG0/ { print $2}'`
It's possible to modify two shell variables only calling one time to AWK? Perhaps defining two shell variables and modifying in a AWK block.. thanks!!

Regards,
Reply With Quote
Forum Sponsor
  #2  
Old 12-26-2007
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Code:
/PIN0/  { printf "PIN=%s\n", $2  }
/SIG0/  { printf "SIG=%s\n", $2  }
Code:
$ eval `gsmctl -d /dev/ttyS0 pin sig | awk -f awkfile`
$ echo $PIN $SIG
READY 31
Reply With Quote
  #3  
Old 12-26-2007
Registered User
 

Join Date: Jan 2006
Posts: 23
fpmurphy, thanks for your reply ;-)

I want to use only one script/file.. using awk -f I need at least two files, is there any solution to make this only with one script? perhaps using another way instead of awk? Thanks!!

Regards,
Reply With Quote
  #4  
Old 12-26-2007
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 570
Quote:
Originally Posted by Santi View Post
I want to use only one script/file.. using awk -f I need at least two files, is there any solution to make this only with one script? perhaps using another way instead of awk?

Regards,
Code:
gsmctl -d /dev/ttyS0 pin s | xargs | read X PIN Y SIG
echo $PIN
echo $SIG
Reply With Quote
  #5  
Old 12-26-2007
rikxik's Avatar
Registered User
 

Join Date: Dec 2007
Posts: 105
Quote:
Originally Posted by shamrock View Post
Code:
gsmctl -d /dev/ttyS0 pin s | xargs | read X PIN Y SIG
echo $PIN
echo $SIG
Not nitpicking - the above does not work with sh/bash - only in ksh. This should work with all three:

Code:
set `gsmctl -d /dev/ttyS0 pin s |awk '{print $2}'`
echo $1 $2
HTH
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0