The below awk script that i did is working fine. It gives me the results that i want. But, the script is not smart and very long as i have 8 conditions to meet. The sample script below only show 2 conditions.
sample inputfile
Sample output
I don't have any problem with the output, all i want to know is much better way to simplify this in awk. Can anyone help/advise me about this. Thanks
Last edited by redse171; 10-03-2014 at 10:47 PM..
Reason: wrong output
how can i use two or multiple statements in the if part
of an awk code
for example
i want to check two flag if they are true i will write some print
operations and increase the counter.
here is the c version of the code that i want to write:
counter=0;
if (flag1==1 && flag2==0) {... (7 Replies)
Hi,
Despite reading the Conditional Statements chapter in the O'Reilly Sed & Awk book several times and looking at numerous examples, I cannot for the life of me get any kind of if ... else statement to work in my awk scripts! My scripts work perfectly (as they are written at least) and do what... (4 Replies)
I have an awk statement that works but I am calling awk twice and I know there has to be a way to combine the two statements into one. The purpose is to pull out just the ip address from loopback1.
cat config.txt | nawk 'BEGIN {FS="\n"}{RS="!"}{if ( $0 ~ "interface loopback1" ) print$4}' | nawk... (5 Replies)
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)
Hello UNIX Community,
I have file that contains the following data:
testAwk2.csv
rabbit penguin goat
giraffe emu ostrich
hyena elephant panda
dog cat pig
lizard snake antelope
platypus tiger cheetah
lion rhino spider
I then find the character length of the... (1 Reply)
I'm converting some code from ksh on my macbook (Version M 1993-12-28 s+) to an older solaris machine with ksh 88.
I can't seem to figure out this line, it worked on the new shell version.
set -A combo -- $(for x in ${ImageIDs};
do
nawk -v s=$x 'if($2 == s) getline ; getline if ($1 ==... (2 Replies)
Hi,
I have the following two awk statements which I'd like to consolidate into one by piping the output from the first into the second awk statement (rather than having to write kat.txt out to a file and then reading back in).
awk 'BEGIN {FS=OFS=" "} {printf("%s ", $2);for (x=7; x<=10;... (3 Replies)
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)
Hello again everyone,
yes, I'm back again for more help! So I'm attempting to read two separate files and generate some XML code from that. My current code is:
BEGIN {
print "<?xml version=\"1.0\" encoding=\"utf-8\">"
print "<Export>"
}
{
x=1;
print "<section name=\"Query" NR "\">"... (5 Replies)
Hi
What is the right structure to use awk with multiple If statements
The following code doesn't work
#
awk '
{
A = $1
}
END {
for ( i = 1; i <= c; i++ )
{
if ( A == 236 && A ==199... (7 Replies)
Discussion started by: khaled79
7 Replies
LEARN ABOUT DEBIAN
mysql::diff::table
MySQL::Diff::Table(3pm) User Contributed Perl Documentation MySQL::Diff::Table(3pm)NAME
MySQL::Diff::Table - Table Definition Class
SYNOPSIS
use MySQL::Diff::Table
my $db = MySQL::Diff::Database->new(%options);
my $def = $db->def();
my $name = $db->name();
my $field = $db->field();
my $fields = $db->fields(); # %$fields
my $primary_key = $db->primary_key();
my $indices = $db->indices(); # %$indices
my $options = $db->options();
my $isfield = $db->isa_field($field);
my $isprimary = $db->isa_primary($field);
my $isindex = $db->isa_index($field);
my $isunique = $db->is_unique($field);
my $isfulltext = $db->is_fulltext($field);
DESCRIPTION
Parses a table definition into component parts.
METHODS
Constructor
new( %options )
Instantiate the objects, providing the command line options for database access and process requirements.
Public Methods
Fuller documentation will appear here in time :)
o def
Returns the table definition as a string.
o name
Returns the name of the current table.
o field
Returns the current field definition of the given field.
o fields
Returns an array reference to a list of fields.
o primary_key
Returns a hash reference to fields used as primary key fields.
o indices
Returns a hash reference to fields used as index fields.
o options
Returns the additional options added to the table definition.
o isa_field
Returns 1 if given field is used in the current table definition, otherwise returns 0.
o isa_primary
Returns 1 if given field is defined as a primary key, otherwise returns 0.
o isa_index
Returns 1 if given field is used as an index field, otherwise returns 0.
o is_unique
Returns 1 if given field is used as unique index field, otherwise returns 0.
o is_fulltext
Returns 1 if given field is used as fulltext index field, otherwise returns 0.
COPYRIGHT AND LICENSE
Copyright (c) 2000-2011 Adam Spiers. All rights reserved. This program is free software; you can redistribute it and/or modify it under the
same terms as Perl itself.
SEE ALSO
mysqldiff, MySQL::Diff, MySQL::Diff::Database, MySQL::Diff::Utils
AUTHOR
Adam Spiers <mysqldiff@adamspiers.org>
perl v5.14.2 2012-04-06 MySQL::Diff::Table(3pm)