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 and shell scripting languages 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 12:16 PM
variables in shell viko Shell Programming and Scripting 2 03-03-2008 11:09 PM
How to modify an existing pdf with unix shell commands fandwick UNIX for Advanced & Expert Users 3 06-08-2007 11:28 AM
Using shell variables In awk nortypig Shell Programming and Scripting 11 08-24-2006 01:48 AM
Is it possible in a shell script to modify itself ?? sehgalniraj Shell Programming and Scripting 5 03-23-2005 12:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-26-2007
Santi Santi is offline
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,
  #2 (permalink)  
Old 12-26-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,938

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

  #3 (permalink)  
Old 12-26-2007
Santi Santi is offline
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,
  #4 (permalink)  
Old 12-26-2007
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
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

  #5 (permalink)  
Old 12-26-2007
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0