|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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' |
|
#4
|
|||
|
|||
|
Not my orgy, but point taken.
|
|
#5
|
|||
|
|||
|
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). |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Help needed with ksh scripting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|