UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 18th, 2004, 05:27 PM
yogi27 yogi27 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: Dallas
Posts: 50 yogi27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Help needed with ksh scripting

Hi,

I have written a script which has a line: echo 'VpcId=`grep -w '$2' msbout | grep -w 00005 | awk '{print \$7}'`'

I have done it this way because I want the output of my script to contain: VpcId=`grep -w 9 msbout | grep -w 00005 | awk '{print $7}'`

I have used '$2' instead of $2 so that I can use it as a command line argument and hence get the value 9.

My problem is that the awk part does not get echo'ed properly. The output file has: VpcId=`grep -w 2 msbout | grep -w 00005 | awk {print $7}`.

I don't get the single quotes on the print $7 part of the command.

Can someone please help me out with this. Thanks.

-Yogesh.

Reply With Quote
  #2  
Old October 19th, 2004, 07:40 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
I often have to put quotes back into a statement and use sed to do it (see below)


$ echo 'VpcId=`grep -w '$2' msbout | grep -w 00005 | awk +{print $7}+`' |sed "s/+/'/g"
VpcId=`grep -w msbout | grep -w 00005 | awk '{print $7}'`


Note that
1) I don't think you should be escaping the $ in $7
2) I don't have a $2 as I'm running the command from the command prompt

Reply With Quote
  #3  
Old October 19th, 2004, 07:58 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
please andyb1ack
do not propagate such statements
unix really can more|better
this thread is duplicated, assuming the format of the other
eg: 0x0024 2 0x0000 00 009 00005 0x2002
instead of your grep|awk|sed orgie, simply try:
sed -n '/\(.*\) 2 \(.*\) \(.*\) \(.*\) 00005 \(.*\)/\7/p'
that's called: regexp
i don't like '2' and '00005' and would say:
FIRST=" 2 "
SCND=" 00005 "
sed -n "/\(.*\)$FIRST\(.*\) \(.*\) \(.*\)$SCND\(.*\)/\7/p"

note " intead of '
and the spaces in FIRST and SCND
this is an example, on a productive sys i also will be more 'matching'

Reply With Quote
  #4  
Old October 19th, 2004, 08:07 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Not my orgy, but point taken.

Reply With Quote
  #5  
Old October 28th, 2004, 09:39 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
Hmmm... still a valid answer of mine too.

I've just need to use that technique (use another character and then sed it to a single quote).

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help needed with ksh scripting


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway