Sponsored Content
Full Discussion: Combining awk tests
Top Forums UNIX for Dummies Questions & Answers Combining awk tests Post 302341374 by treesloth on Wednesday 5th of August 2009 06:43:47 PM
Old 08-05-2009
Ah, so apparently it only works with the ~ "contains" operator, not == and !=, etc:

Code:
> cat datafile
Bob  here
Jane here
Ron  absent
Linda absent
Paul unknown

> awk '$1 ~/Bob|Linda/ {print $0}' datafile
Bob  here
Linda absent

> awk '$1 == /Bob|Linda/ {print $0}' datafile

> awk '$1 != /Bob|Linda/ {print $0}' datafile
Bob  here
Jane here
Ron  absent
Linda absent
Paul unknown

That's a shame, but it's more than I had before. Thanks for the reply.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help combining lines in awk

I seem to have gotten myself in over my head on this one. I need help combining lines together. I have a text file containing 24,000 lines (exactly why I need awk) due to bad formatting it has separated the lines (ideally it should be 12,000 lines total). Example of file: ... (2 Replies)
Discussion started by: blueheed
2 Replies

2. Shell Programming and Scripting

combining fields in awk

I am using: ps -A -o command,%cpu to get process and cpu usage figures. I want to use awk to split up the columns it returns. If I use: awk '{print "Process: "$1"\nCPU Usage: "$NF"\n"}' the $NF will get me the value in the last column, but if there is more than one word in the... (2 Replies)
Discussion started by: json4639
2 Replies

3. Shell Programming and Scripting

Combining two awk scripts

I have a file like this consisting of blocks separated by > of two number X and T > 10 0 13 5.92346 16 10.3106 19 13.9672 22 16.9838 25 19.4407 28 21.4705 31 23.1547 34 24.6813 37 26.0695 40 27.3611 43 28.631 46 29.8366 49 30.9858 52 32.0934 55 33.1458 (6 Replies)
Discussion started by: kristinu
6 Replies

4. Shell Programming and Scripting

Combining awk statements

I have a pretty simple script below: #!/bin/sh for i in *.cfg do temp=`awk '/^InputDirectory=/' ${i}` input_dir=`echo ${temp} | awk '{ print substr( $0, 16) }'` echo ${input_dir} done As you can see its opening each cfg file and searching for the line that has "InputDirectory="... (3 Replies)
Discussion started by: ssbsts
3 Replies

5. Shell Programming and Scripting

combining awk and sed

Hi experts, I have a requirement, In which I need to display the first and last line of a zip file where the line starts with "L". I've writen the code like below using sed and awk. gunzip -c 20110203.1104.gz | awk '$1 ~ "^L" {print substr($0,178,15)}' | sed -n '1p;$p' Is it possible to do it... (8 Replies)
Discussion started by: senthil.ak
8 Replies

6. Shell Programming and Scripting

How to combining awk commands?

I can achieve two tasks with 2 different awk commands: 1) awk -F";;WORD" '{print $2}' file | sed '/^$/d' #to find surface_word 2) awk -F"bw:|gloss:" '// {print $2}' file | sed '/\//!d; s:/*+*: + :g; s:^+::; s: *+ *$::;' #to find segmentation of surface_word Number 1) finds surface_word... (7 Replies)
Discussion started by: Viernes
7 Replies

7. Shell Programming and Scripting

awk problem - combining awk statements

i have a datafile that has several lines that look like this: 2,dataflow,Sun Mar 17 16:50:01 2013,1363539001,2990,excelsheet,660,mortar,660,4 using the following command: awk -F, '{$3=strftime("%a %b %d %T %Y,%s",$3)}1' OFS=, $DATAFILE | egrep -v "\-OLDISSUES," | ${AWK} "/${MONTH} ${DAY}... (7 Replies)
Discussion started by: SkySmart
7 Replies

8. Shell Programming and Scripting

Combining echo and awk

i have a script that has many lines similar to: echo $var | awk -F"--" '{print $2}' as you can see, two commands are being run here. echo and awk. id like to combine this into one awk statement. i tried: awk -F"--" "BEGIN{print $var; print $2}" but i get error messages. (10 Replies)
Discussion started by: SkySmart
10 Replies

9. Shell Programming and Scripting

What am I doing wrong in awk with multiple tests?

awk -v pat="$pattern" 'NR == 1 {print $0}; $0 ~ pat {print $0}' infile.csv > outfile.csv The first row of my file contains headers so I want them. Otherwise, I want only lines containing the BASH variable pattern which I am passing to awk with -v. This is giving me all the lines containing... (6 Replies)
Discussion started by: Michael Stora
6 Replies

10. Shell Programming and Scripting

awk Pattern Matching for PING tests

I have a script that logs into a server and pings several other servers in order to verify IP path between servers. The output can look like this, if good pings: Response from 1.1.1.4;_id=0, vlan_prio=0): seq=0 time=91.547 ms. Response from 1.1.1.4;_id=0, vlan_prio=0): seq=1 time=61.176 ms.... (7 Replies)
Discussion started by: he204035
7 Replies
MicroMason::ExecuteCache(3pm)				User Contributed Perl Documentation			     MicroMason::ExecuteCache(3pm)

NAME
Text::MicroMason::ExecuteCache - Use a Cache for Template Results SYNOPSIS
Instead of using this class directly, pass its name to be mixed in: use Text::MicroMason; my $mason = Text::MicroMason->new( -ExecuteCache ); Use the standard compile method to parse a template into a subroutine: my $subref = $mason->compile( text=>$template ); print $subref->( 'name'=>'Dave' ); The template does not have to be interpreted the second time because the results are cached: print $subref->( 'name'=>'Dave' ); # fast second time When run with different arguments, the template is re-interpreted and the results stored: print $subref->( 'name'=>'Bob' ); # first time for Bob print $subref->( 'name'=>'Bob' ); # fast second time for Bob DESCRIPTION
Caches the output of templates. Note that you should not use this feature if your template code interacts with any external state, such as making changes to an external data source or obtaining values that will change in the future. (However, you can still use the caching provided by Text::MicroMason::CompileCache.) Public Methods compile() Wraps each template that is compiled into a Perl subroutine in a memoizing closure. Supported Attributes execute_cache Defaults to an instance of Text::MicroMason::Cache::Simple. This module uses a simple cache interface that is widely supported: the only methods required are "get($key)" and "set($key, $value)". You can use the simple cache classes provided in the Text::MicroMason::Cache:: namespace, or select other caching modules on CPAN that support the interface described in Cache::Cache. SEE ALSO
For an overview of this templating framework, see Text::MicroMason. This is a mixin class intended for use with Text::MicroMason::Base. For distribution, installation, support, copyright and license information, see Text::MicroMason::Docs::ReadMe. perl v5.10.1 2007-01-29 MicroMason::ExecuteCache(3pm)
All times are GMT -4. The time now is 12:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy