Sponsored Content
Top Forums Shell Programming and Scripting AWK Script and Commandline difference Post 302534988 by MrSnail on Wednesday 29th of June 2011 10:08:24 AM
Old 06-29-2011
AWK Script and Commandline difference

Hey there,

I just stumbled upon a difference between using awk on the commandline and using it in a shellscript.

I have a variable, e.g.: PROG=vim
then i want to check if the package with this name is installed: TEMPVAL=$(dpkg -l | awk '{ if ($2 == "$PROG") print $2 }') (Im using Tempval later in an condition to check if it is installed)
Running this on the commandline works fine. In the shellscript TEMPVAL is always empty.

btw "toinstall" just contains some package names to be installed and comments prefixed with #

full script:
Code:
#!/bin/bash

for prog in `cat toinstall | grep -vP "^#" | grep -vP "^$"`
do
    TEMPVAL=$(`dpkg -l | awk '{ if ($2 == "${prog}") print $2}'`)
    if [  "$TEMPVAL" == "" ]
    then
    sudo apt-get install -y $prog
    fi
done

bash -x output:
Code:
+ for prog in '`cat toinstall | grep -vP "^#" | grep -vP "^$"`'
+++ dpkg -l
+++ awk '{ if ($2 == "${prog}") print $2}'
+ TEMPVAL=
+ '[' '' == '' ']'
+ sudo apt-get install -y vim

Whats the Problem?Smilie I already tried playing with the quotation, but nothing worked. Hope somebody can help me. I'd also appreciate hints or tips if theres a more convenient way of doing what i want to do Smilie

Greetings, MrSnail
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to go to a different dir to run a commandline prompt in that dir

Hi, I need to know how I'll be able to write a script that can goto a different dir where I don't have access to read,write and execute and also to run a commandline prompt in that dir with one file whose path has to be specified in that command. Will I be able to do this? Any ideas or... (2 Replies)
Discussion started by: ann_124
2 Replies

2. Shell Programming and Scripting

How to determine if a script (perl) was called from a CRON job or commandline

Hi, Is there a way to determine if a Script is called from a CRON job or from a commandline Gerry. (2 Replies)
Discussion started by: jerryMcguire
2 Replies

3. Shell Programming and Scripting

Handling values with space while passing commandline argument from wrapper script in KSH

Hi there, I have a wapper script which passes the argument from command prompt to inner script.. It works fine as long as the argument containing single word. But when value contains multiple word with space, not working as expected. I tried my best, couldn't find the reason. Gurus, pls.... (2 Replies)
Discussion started by: kans
2 Replies

4. Shell Programming and Scripting

How to print and append output of nawk script in commandline and as well into a file?

Hi All, I am working on nawk script, has the small function which prints the output on the screen.Am trying to print/append the same output in a file. Basically nawk script should print the output on the console/screen and as well it should write/append the same result to a file. script :... (3 Replies)
Discussion started by: Optimus81
3 Replies

5. UNIX for Dummies Questions & Answers

Shell script - getting Time difference using awk

Hi..I have the data in a file like in this format, and I need the output time difference in seconds by using awk command. Start date/time and end date/time given in column 2,3 & 4,5. Please assist how to write shell script. File1.txt JOB1 10/09/2013 17:42:16 10/09/2013 17:43:46 SU 6202685/1... (4 Replies)
Discussion started by: mprithvi
4 Replies

6. Shell Programming and Scripting

sed commands success / fail from commandline vs ksh script

solaris 5.10 Generic_138888-03 sun4v sparc SUNW,Sun-Fire-T200 I need a sed command that tests true when presented with lines that contain either forward and backslash. input file: c:/myFile.txt c:\yourFile.txt It doesn't appear that sed (in my environment anyway) supports... (4 Replies)
Discussion started by: msutfin
4 Replies

7. Shell Programming and Scripting

Script executed by Cron or commandline

Hello all, I have a question regarding the difference betwen cron and command line. What I would like to do is to print a statement into a logfile if a script has been executed from cron or from command line. It should be as: #!/bin/bash if <Check if this script has been... (3 Replies)
Discussion started by: API
3 Replies

8. Shell Programming and Scripting

awk script to find time difference between HTTP PUT and HTTP DELETE requests in access.log

Hi, I'm trying to write a script to determine the time gap between HTTP PUT and HTTP DELETE requests in the HTTP Servers access log. Normally client will do HTTP PUT to push content e.g. file_1.txt and 21 seconds later it will do HTTP DELETE, but sometimes the time varies causing some issues... (3 Replies)
Discussion started by: Juha
3 Replies

9. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

How to put a difference calculation in my awk script ?

Hello, For my CGI, I have this script : #!/bin/bash echo "Content-type: text/html" echo "" echo ' <html> <head> <meta http-equiv="Content-Type" content="test/html"; charset=UTF-8"> <title> CLF MONITORING </title> <h1> FRAME... (4 Replies)
Discussion started by: Tim2424
4 Replies
SUMO(1) 							   User Commands							   SUMO(1)

NAME
SUMO - Importer of polygons and POIs for the road traffic simulation SUMO SYNOPSIS
polyconvert [OPTION]* DESCRIPTION
SUMO polyconvert Version 0.15.0 Copyright (C) 2001-2012 DLR and contributors; http://sumo.sourceforge.net Importer of polygons and POIs for the road traffic simulation SUMO. Configuration Options: -c, --configuration-file FILE Loads the named config on startup --save-configuration FILE Saves current configuration into FILE --save-template FILE Saves a configuration template (empty) into FILE --save-schema FILE Saves the configuration schema into FILE --save-commented Adds comments to saved template, configuration, or schema Input Options: -n, --net-file FILE Loads SUMO-network FILE as reference to offset and projection --dlr-navteq-poly-files FILE Reads polygons from FILE assuming they're coded in DLR-Navteq (Elmar)-format --dlr-navteq-poi-files FILE Reads pois from FILE+ assuming they're coded in DLR-Navteq (Elmar)-format --visum-files FILE Reads polygons from FILE assuming it's a Visum-net --xml-files FILE Reads pois and shapes from FILE assuming they're coded in XML --osm-files FILE Reads pois from FILE+ assuming they're coded in OSM --osm.keep-full-type The type will be made of the key-value - pair. --osm.use-name The id will be set from the given 'name' attribute. --shapefile-prefixes FILE Reads shapes from shapefiles FILE+ --shapefile.guess-projection Guesses the shapefile's projection --shapefile.id-column FILE Defines in which column the id can be found --type-file FILE Reads types from FILE Output Options: -o, --output-file FILE Write generated polygons/pois to FILE Projection Options: --simple-projection Uses a simple method for projection --proj.scale INT Number of places to shift decimal point to right in geo-coordinates --proj.utm Determine the UTM zone (for a universal transversal mercator projection based on the WGS84 ellipsoid) --proj.dhdn Determine the DHDN zone (for a transversal mercator projection based on the bessel ellipsoid) --proj STR Uses STR as proj.4 definition for projection --proj.inverse Inverses projection Pruning Options: --prune.in-net Enables pruning on net boundaries --prune.in-net.offsets STR Uses STR as offset definition added to the net boundaries --prune.boundary STR Uses STR as pruning boundary --prune.keep-list STR Items in STR will be kept though out of boundary --prune.explicit STR Items with names in STR will be removed Processing Options: --offset.x FLOAT Adds FLOAT to net x-positions --offset.y FLOAT Adds FLOAT to net y-positions Building Defaults Options: --color STR Sets STR as default color --prefix STR Sets STR as default prefix --type STR Sets STR as default type --layer INT Sets INT as default layer --discard Sets default action to discard Report Options: -v, --verbose Switches to verbose output -p, --print-options Prints option values before processing -?, --help Prints this screen -V, --version Prints the current version -W, --no-warnings Disables output of warnings -l, --log FILE Writes all messages to FILE (implies verbose) --message-log FILE Writes all non-error messages to FILE (implies verbose) --error-log FILE Writes all warnings and errors to FILE EXAMPLES
polyconvert -c <CONFIGURATION> run with configuration options set in file REPORTING BUGS
Report bugs at <http://sourceforge.net/apps/trac/sumo/>. Get in contact via <sumo-user@lists.sourceforge.net>. Copyright (C) 2001-2012 DLR and contributors; http://sumo.sourceforge.net SUMO polyconvert Version 0.15.0 is part of SUMO. SUMO is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/gpl.html SUMO polyconvert Version 0.15.0 May 2012 SUMO(1)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy