Sponsored Content
Full Discussion: Variable IF statement in awk
Top Forums Shell Programming and Scripting Variable IF statement in awk Post 302754177 by meike on Thursday 10th of January 2013 07:29:35 AM
Old 01-10-2013
Variable IF statement in awk

I have multiple requirements to run data extracts (with the same basic requriement / resulsts) however the parameters of the extracts change with each request. To help make life easier I am writing a script where the parameters for the specific request are set at the start and then used as needed.
HOWEVER I am having problems with the awk portion of the script.

To simplify matters here is test data and script to explain the problem.

data file as follows (test)
Code:
1 a
2 b
3 c
4 d

in this instance I want to output record 3 c

script as follows:
Code:
parm='&& ($2=="c")';
cat test | awk -v parm="$parm" '{if ((1==1) parm) {print $0}}'

this is outputting the entire file and not just the 3rd record
(note: the (1==1) is a failsafe incase there is no parameter passed)

Last edited by Franklin52; 01-10-2013 at 08:37 AM.. Reason: Please use code tags for data and code samples
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using variable in case statement

I want to do this: Ex 1: case $answer in 1|2|3|4|5) echo $answer;; x) break;; *) echo "Invalid selection. Try again.";; esac But I need the part "1|2|3|4|5" to be fetched from a variable, like so: Ex 2: case $answer in $cases) echo $answer;; x) break;; *) echo "Invalid... (2 Replies)
Discussion started by: fialia
2 Replies

2. Shell Programming and Scripting

Can't interpret variable in if statement

Can someone help me out here. I can't get this piece of code to work. i.e. $ALL_EVENTS does not get interpreted in the if brackets. The first part is the code, the second part is the execution of the code. Note: $ALL_EVENTS does equal 2, but there is no value once passed to the if statement. ... (4 Replies)
Discussion started by: jwholey
4 Replies

3. Shell Programming and Scripting

If statement in awk with external variable

So I have a if statement inside an awk to check if $2 of a awk equals a specific IP but the test fails. So here is what I have. # !/bin/sh echo "Enter client ID" read ID echo "Enter month (01, 02, 03)" read month echo "Enter day (03, 15)" read day echo "Enter Year (07, 08)" read... (6 Replies)
Discussion started by: doublejz
6 Replies

4. Shell Programming and Scripting

Assigning Variable to AWK statement

Hi, The following command runs on in the Korn shell prompt. however i want to output the value of this to a variable. Can anyone provide a solution? echo 'ABC,DEF,"G,HI,J",KLM,"MNi,O"'| awk -F "\"" '{for(i=1;i<=NF;i++){if(i%2)gsub("\,","~^~",$i)}}1' (2 Replies)
Discussion started by: ladarlsan
2 Replies

5. Shell Programming and Scripting

Select variable within a if statement

i want to select a variable created and use it in a if statement, but not getting the desired results LINE='device for 0101a01: lpd://172.25.41.111:515' prt=`echo $LINE | awk '{print $3 }' | cut -c 1-7` echo $prt My if statement to select just what i want.. IFS=$":" while read prt... (11 Replies)
Discussion started by: ggoliath
11 Replies

6. Shell Programming and Scripting

Variable is not evaluated in awk statement

Dear All, I have one problem in my script, awk statement as 1. it is not evaluate the second variable $stake but the first one $channel is being done. 2.I want to assign the whole awk statement to a variable actual_code which is not being executed in my script. #!/usr/bin/sh echo "Enter... (3 Replies)
Discussion started by: chinmayadalai
3 Replies

7. Shell Programming and Scripting

awk - updating variable in if statement

I have another question I am stuck at :wall: I have a text file with two columns, like so... 2 0.0627279 3 0.0794451 4 0.108705 5 0.137739 6 0.190394 7 0.217407 8 0.241764 9 0.344458 10 0.460762 I'd like to go through the file line by line until the value in the second column... (3 Replies)
Discussion started by: origamisven
3 Replies

8. Shell Programming and Scripting

if then else; no variable match but statement executes anyway.

My first then statement is executing even though there is no match between the variables. each subsequent if then statement is also executing. Why do they execute when there is no match in the dates? yr=`date +%y` date1=12-31-$yr date=`date +%m-%d-%y` set -vx if ; ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

9. Shell Programming and Scripting

Variable on If Statement

Hi, I am tasked to modify soem script and I come accross a line which I dont fully understand. I tried searching online but I couldnt get a good explanation on it. Here it the part of the code: PAY_RT=`cat $TEMPFILE | cut -f2 -d","` if ; then PAY_RT=R fi What is... (3 Replies)
Discussion started by: The One
3 Replies

10. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies
tableau-parm(1) 														   tableau-parm(1)

NAME
tableau-parm - Tableau Write-blocking Bridge Query/Command Utility SYNOPSIS
tableau-parm [-r] device DESCRIPTION
tableau-parm is designed to interact with write-blocking forensics bridges produced by Tableau, LLC. It can be used to query bridges for various bridge and device data, as well as to disable DCO regions. OPTIONS
tableau-parm accepts the following parameters: -r Directs tableau-parm to permanently remove a DCO, if it exists. THIS WILL MODIFY THE STATE OF THE DRIVE. USE AT YOUR OWN RISK! (It is recommended for forensics investigations, that a full drive image be taken before this command is run, and then again afterward if a DCO was detected originally.) Note: after running this, you'll need to restart the Tableau bridge for it to correctly detect the changes. device Required argument. Specifies the device file for the bridge/drive to be queried. This must be a device presenting SCSI emulation. Under Linux, all USB and FireWire mass storage devices behave like SCSI devices. Once a bridge and drive are plugged in and powered on, one can generally find out what the device was dynamically mapped to by running: dmesg | tail -20 OUTPUT
tableau-parm generates simple output with one data value per line, interspersed with blank lines and section headers. This output format is subject to change. EXAMPLES
To query a bridge which is mapped to /dev/sda: tableau-parm /dev/sda To remove a DCO from the hard drive on /dev/sda: tableau-parm -r /dev/sda BUGS
Older versions of ATA and SATA Tableau firmwares didn't properly handle HPA and DCO on some types of drives. Be sure to upgrade your block- ers' firmwares using the firmware update utility, version 4.2 or later, which was released on July 5, 2007. This is not really a bug, but something to note: when a drive has both an HPA and DCO section, and the DCO is removed, the HPA is removed with it. This is how the bridge firmware works, and isn't something controlled by tableau-parm. Just something to be aware of. CREDITS
Copyright (C) 2007,2009 Timothy D. Morgan Copyright (C) 1999,2001,2006,2007 D. Gilbert tableau-parm was written by Timothy D. Morgan using portions of SCSI example code written by D. Gilbert. Tableau, LLC cooperated in the development of this tool by providing documentation on the proprietary SCSI interfaces and assisted in test- ing. Without their help, this tool would not have been possible. Tableau, LLC does not endorse or warrant this code in any way. LICENSE
Please see the file "LICENSE" included with this software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more details. SEE ALSO
hdparm(1) sdparm(1) Forensics Utilities 30 September 2009 tableau-parm(1)
All times are GMT -4. The time now is 02:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy