Sponsored Content
Full Discussion: awk search syntax
Top Forums Shell Programming and Scripting awk search syntax Post 303043218 by migurus on Tuesday 21st of January 2020 01:17:52 PM
Old 01-21-2020
awk search syntax

I need help with understanding awk search feature.


Here I am trying to search by 4th field in this file:


Code:
$ cat xx
471013,A20,asd,100,FEATURE UNKNOWN
171014,A22,sdf,101,FEATURE WITH SUB-ELEMENT
172822,20X,xcv,102,SUB-ELEMENT
101102,22X,asd,103,CODED

When I try the search feature I get nothing:
Code:
$ awk -F, '/$4 ~ "101"/{print}' xx        

$

When I just use IF statement it works as expected:
Code:
$ awk -F, '{ if($4 == 101)print; }' xx
171014,A22,sdf,101,FEATURE WITH SUB-ELEMENT
$

Please help me understand what do I do wrong in using the search // syntax
Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK Syntax errors :/

I recently started as an intern and my manager wanted to see how well I would handle Korn Bourne shell scripting without any prior experience, I have prior programming experience but I keep running into syntax errors with AWK. Please take a look at my simple code and tell me what stupid mistake... (6 Replies)
Discussion started by: yongho
6 Replies

2. Shell Programming and Scripting

Help with Awk Syntax

I have written many awk commands which go in multiple lines. I have this confusion many times. Some time they work if i dont terminate them with "\" but some time error. Some time in "if" statements between if and else if i dont use ";" it gives error but sometimes it doesnt. The below... (4 Replies)
Discussion started by: pinnacle
4 Replies

3. Shell Programming and Scripting

awk syntax help

I don't get correct output when I run this command line: nmap -sP failedhost.com | grep -i failed | awk -F '{print $6}' I basically want it to return 'failedhost.com' but its just showing the output of the nmap scan. (8 Replies)
Discussion started by: streetfighter2
8 Replies

4. Shell Programming and Scripting

AWK syntax

Hi I am trying to understand AWK syntax so I tried this command which gives me the home directory of root awk 'BEGIN { FS = ":"} {if ($1 == "root") print $6 }' /etc/passwd I would know what are the following commands doing. The first one prints all /etc/passwd, second prints nothing. ... (4 Replies)
Discussion started by: wakatana
4 Replies

5. UNIX for Dummies Questions & Answers

awk syntax

Little bit confusing while using awk :confused::confused: In Sed while pattern search we can use "(double quotes) i mean $a=hello $cat file.txt |sed -n "/$a/p"this thing work fine But if i use it in awk it's not working How could i do the substitution of pattern by a variables and the... (1 Reply)
Discussion started by: posix
1 Replies

6. Shell Programming and Scripting

AWK syntax help

i have a ksh code that needs to be written in AWK. can someone please help me here? :( if }" | grep -c "$2") -gt 0 ] ; then print - "found $2 in array ignore" else print - "did not find $2 in array ignore" fi ignore=4ty56r ignore=er45ty . . . ignore=frhtg2 (27 Replies)
Discussion started by: usustarr
27 Replies

7. AIX

Help with syntax using AWK

I have a file which is comma separated and has quotes. I can use this command and awk -F"," '{ if ($4=="01" print $0 }' test.txt But this doesn't fetch me the data.since it has quotes. If the data has no quotes,the above command works fine. In Unix you can skip quote \" but this doesn't work.... (7 Replies)
Discussion started by: ganesnar
7 Replies

8. Shell Programming and Scripting

Syntax error using Awk

more report2.txt how to modify the AWK to print above out put for given n no of inputs using report2.txt file? out put should be (3 Replies)
Discussion started by: kanakaraju
3 Replies

9. Shell Programming and Scripting

awk syntax

Hi I have a bash file which will split a big file to many small files. But I got a syntax error.H="$(head -1 CCC.tped)" awk 'print $0 > $1 ".tped"' CCC.tped for f in $(ls *.tped); do echo "$H\n" "$(cat $f)" >$f; done And -bash-4.1$ bash split awk: print $0 > $1".tped" awk: ^ syntax error... (3 Replies)
Discussion started by: zhshqzyc
3 Replies

10. Shell Programming and Scripting

Help with the awk syntax

Hello Experts: While writing a script to help one of the posts on here, I end up writing a wrong one. I am very much eager to know how this can be corrected. Aim was to not print specified columns - lets say out of 100 fields, need to print all but 5th, 10th, 15th columns. Someone already... (13 Replies)
Discussion started by: juzz4fun
13 Replies
feature(3pm)						 Perl Programmers Reference Guide					      feature(3pm)

NAME
feature - Perl pragma to enable new features SYNOPSIS
use feature qw(switch say); given ($foo) { when(1) { say "$foo == 1" } when ([2,3]) { say "$foo == 2 || $foo == 3" } when (/^a[bc]d$/) { say "$foo eq 'abd' || $foo eq 'acd'" } when ($_ > 100) { say "$foo > 100" } default { say "None of the above" } } use feature ':5.10'; # loads all features available in perl 5.10 DESCRIPTION
It is usually impossible to add new syntax to Perl without breaking some existing programs. This pragma provides a way to minimize that risk. New syntactic constructs, or new semantic meanings to older constructs, can be enabled by "use feature 'foo'", and will be parsed only when the appropriate feature pragma is in scope. Lexical effect Like other pragmas ("use strict", for example), features have a lexical effect. "use feature qw(foo)" will only make the feature "foo" available from that point to the end of the enclosing block. { use feature 'say'; say "say is available here"; } print "But not here. "; "no feature" Features can also be turned off by using "no feature "foo"". This too has lexical effect. use feature 'say'; say "say is available here"; { no feature 'say'; print "But not here. "; } say "Yet it is here."; "no feature" with no features specified will turn off all features. The 'switch' feature "use feature 'switch'" tells the compiler to enable the Perl 6 given/when construct. See "Switch statements" in perlsyn for details. The 'say' feature "use feature 'say'" tells the compiler to enable the Perl 6 "say" function. See "say" in perlfunc for details. the 'state' feature "use feature 'state'" tells the compiler to enable "state" variables. See "Persistent Private Variables" in perlsub for details. the 'unicode_strings' feature "use feature 'unicode_strings'" tells the compiler to treat all strings outside of "use locale" and "use bytes" as Unicode. It is available starting with Perl 5.11.3. See "The "Unicode Bug"" in perlunicode for details. FEATURE BUNDLES
It's possible to load a whole slew of features in one go, using a feature bundle. The name of a feature bundle is prefixed with a colon, to distinguish it from an actual feature. At present, the only feature bundle is "use feature ":5.10"" which is equivalent to "use feature qw(switch say state)". Specifying sub-versions such as the 0 in 5.10.0 in feature bundles has no effect: feature bundles are guaranteed to be the same for all sub-versions. IMPLICIT LOADING
There are two ways to load the "feature" pragma implicitly : o By using the "-E" switch on the command-line instead of "-e". It enables all available features in the main compilation unit (that is, the one-liner.) o By requiring explicitly a minimal Perl version number for your program, with the "use VERSION" construct, and when the version is higher than or equal to 5.10.0. That is, use 5.10.0; will do an implicit use feature ':5.10'; and so on. Note how the trailing sub-version is automatically stripped from the version. But to avoid portability warnings (see "use" in perlfunc), you may prefer: use 5.010; with the same effect. perl v5.12.5 2012-11-03 feature(3pm)
All times are GMT -4. The time now is 06:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy