Sponsored Content
Top Forums Shell Programming and Scripting Awk, function of underscore char. Post 302888230 by Scrutinizer on Thursday 13th of February 2014 09:52:39 AM
Old 02-13-2014
It sets an array element with index $0 to the value 1. In the second part, if checks if for $4 in the second file there is an array element with a value other than 0 or "" and if so, it does not print the record.

Another (slightly better) way of doing it would be:
Code:
awk -F, 'NR==FNR{A[$0]; next}!($4 in A)' exclude infile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

usage of underscore in awk

Hi what is the purpose of using underscore in awk. I suppose it is for defining macro's and reducing repeatation but can some one show me an example? (6 Replies)
Discussion started by: ahmedwaseem2000
6 Replies

2. Shell Programming and Scripting

Regex/sed - matching any char,space,underscore between : and /

trying to remove the portion in red: Data: mds_ar/bin/uedw92wp.ksh: $AI_SQL/wkly.sql mds_ar/bin/uedw92wp.ksh: $EDW_TMP/wkly.sql output to be: mds_ar/bin/uedw92wp.ksh: wkly.sql mds_ar/bin/uedw92wp.ksh: wkly.sql SED i'm trying to use: sed 's/:+\//: /g' input_file.dat >... (11 Replies)
Discussion started by: danmauer
11 Replies

3. Shell Programming and Scripting

ksh function getopts get leading underscore unless preceded by hyphen

If I call my function with grouped options: "logm -TDIWEFO 'message' ", then only the "T" gets parsed correctly. The subsequent values returned have underscores prefixed to the value: "_D", "_I", etc. If I "logm -T -DIWEFO 'message' ", the "T" and the "D" are OK, but "I" through "O" get the... (2 Replies)
Discussion started by: kchriste
2 Replies

4. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

5. Programming

unable to send a char parameter from main to a function

why does this not work? #include <stdio.h> #include <stdlib.h> char getFileMode(char charChanger) { char filetype; /*var to hold the value to be returned*/ filetype = charSetter; /*set filetype to "l" if it is a symlink*/ return filetype; } int main(void){ char... (8 Replies)
Discussion started by: bluetxxth
8 Replies

6. Programming

STL algorithm merge() function to concatenate char arrays

When the STL generic algorithm's merge() function is used to merge two char arrays, the output is not as expected. Below is the program I tried with. #include <iostream> #include <algorithm> #include <cstring> #include <deque> #include <iterator> using namespace std; int main() { ... (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. Programming

Small query regarding function "char * strerror(int errnum)"

As this function returns the address of the string corressponding to the errno value provided to it. Can someone please let me know where, in the memory, it could be (on freeBSD). The MAN page tells under the BUG section that "For unknown error numbers, the strerror() function will return its... (5 Replies)
Discussion started by: Praveen_218
5 Replies

8. Shell Programming and Scripting

awk split after second underscore in field

I am trying to split a tab-delimeted file using awk after the second _ in bold. The awk below is close but splits on the first _, and I am not sure how to use the second _. Thank you :). file chr1 92145889 92149424 NM_001195684_exon_0_10_chr1_92145900_r 0 - chr1 92161218 ... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

10. Programming

Segmentation fault when I pass a char pointer to a function in C.

I am passing a char* to the function "reverse" and when I execute it with gdb I get: Program received signal SIGSEGV, Segmentation fault. 0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72 72 *q = *p; Attached is the source code. I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
Devel::Cycle(3) 					User Contributed Perl Documentation					   Devel::Cycle(3)

NAME
Devel::Cycle - Find memory cycles in objects SYNOPSIS
#!/usr/bin/perl use Devel::Cycle; my $test = {fred => [qw(a b c d e)], ethel => [qw(1 2 3 4 5)], george => {martha => 23, agnes => 19} }; $test->{george}{phyllis} = $test; $test->{fred}[3] = $test->{george}; $test->{george}{mary} = $test->{fred}; find_cycle($test); exit 0; # output: Cycle(1): $A->{'george'} => \%B $B->{'phyllis'} => \%A Cycle(2): $A->{'george'} => \%B $B->{'mary'} => @A $A->[3] => \%B Cycle(3): $A->{'fred'} => @A $A->[3] => \%B $B->{'phyllis'} => \%A Cycle(4): $A->{'fred'} => @A $A->[3] => \%B $B->{'mary'} => @A # you can also check weakened references weaken($test->{george}->{phyllis}); find_weakened_cycle($test); exit 0; # output: Cycle(1): $A->{'george'} => \%B $B->{'mary'} => @C $C->[3] => \%B Cycle(2): $A->{'george'} => \%B w-> $B->{'phyllis'} => \%A Cycle(3): $A->{'fred'} => @C $C->[3] => \%B $B->{'mary'} => @C Cycle(4): $A->{'fred'} => @C $C->[3] => \%B w-> $B->{'phyllis'} => \%A DESCRIPTION
This is a simple developer's tool for finding circular references in objects and other types of references. Because of Perl's reference- count based memory management, circular references will cause memory leaks. EXPORT The find_cycle() and find_weakened_cycle() subroutine are exported by default. find_cycle($object_reference,[$callback]) The find_cycle() function will traverse the object reference and print a report to STDOUT identifying any memory cycles it finds. If an optional callback code reference is provided, then this callback will be invoked on each cycle that is found. The callback will be passed an array reference pointing to a list of lists with the following format: $arg = [ ['REFTYPE',$index,$reference,$reference_value], ['REFTYPE',$index,$reference,$reference_value], ['REFTYPE',$index,$reference,$reference_value], ... ] Each element in the array reference describes one edge in the memory cycle. 'REFTYPE' describes the type of the reference and is one of 'SCALAR','ARRAY' or 'HASH'. $index is the index affected by the reference, and is undef for a scalar, an integer for an array reference, or a hash key for a hash. $reference is the memory reference, and $reference_value is its dereferenced value. For example, if the edge is an ARRAY, then the following relationship holds: $reference->[$index] eq $reference_value The first element of the array reference is the $object_reference that you pased to find_cycle() and may not be directly involved in the cycle. If a reference is a weak ref produced using Scalar::Util's weaken() function then it won't contribute to cycles. find_weakened_cycle($object_reference,[$callback]) The find_weakened_cycle() function will traverse the object reference and print a report to STDOUT identifying any memory cycles it finds, including any weakened cycles produced using Scalar::Util's weaken(). If an optional callback code reference is provided, then this callback will be invoked on each cycle that is found. The callback will be passed an array reference pointing to a list of lists with the following format: $arg = [ ['REFTYPE',$index,$reference,$reference_value,$is_weakened], ['REFTYPE',$index,$reference,$reference_value,$is_weakened], ['REFTYPE',$index,$reference,$reference_value,$is_weakened], ... ] Each element in the array reference describes one edge in the memory cycle. 'REFTYPE' describes the type of the reference and is one of 'SCALAR','ARRAY' or 'HASH'. $index is the index affected by the reference, and is undef for a scalar, an integer for an array reference, or a hash key for a hash. $reference is the memory reference, and $reference_value is its dereferenced value. $is_weakened is a boolean specifying if the reference is weakened or not. For example, if the edge is an ARRAY, then the following relationship holds: $reference->[$index] eq $reference_value The first element of the array reference is the $object_reference that you pased to find_cycle() and may not be directly involved in the cycle. Cycle Report Formats The default callback prints out a trace of each cycle it finds. You can control the format of the trace by setting the package variable $Devel::Cycle::FORMATTING to one of "raw," "cooked," or "roasted". The "raw" format prints out anonymous memory references using standard Perl memory location nomenclature. For example, a "Foo::Bar" object that points to an ordinary hash will appear in the trace like this: Foo::Bar=HASH(0x8124394)->{'phyllis'} => HASH(0x81b4a90) The "cooked" format (the default), uses short names for anonymous memory locations, beginning with "A" and moving upward with the magic ++ operator. This leads to a much more readable display: $Foo::Bar=B->{'phyllis'} => \%A The "roasted" format is similar to the "cooked" format, except that object references are formatted slightly differently: $Foo::Bar::B->{'phyllis'} => \%A If a reference is a weakened ref, then it will have a 'w->' prepended to it, like this: w-> $Foo::Bar::B->{'phyllis'} => \%A For your convenience, $Devel::Cycle::FORMATTING can be imported: use Devel::Cycle qw(:DEFAULT $FORMATTING); $FORMATTING = 'raw'; Alternatively, you can control the formatting at compile time by passing one of the options -raw, -cooked, or -roasted to "use" as illustrated here: use Devel::Cycle -raw; Code references (closures) If the PadWalker module is installed, Devel::Cycle will also report cycles in code closures. If PadWalker is not installed and Devel::Cycle detects a CODE reference in one of the data structures, it will warn (once per data structure) that it cannot inspect the CODE unless PadWalker is available. You can turn this warning off by passing -quiet to Devel::Cycle at compile time: use Devel::Cycle -quiet; SEE ALSO
Test::Memory::Cycle Devel::Leak Scalar::Util AUTHOR
Lincoln Stein, <lstein@cshl.edu> COPYRIGHT AND LICENSE
Copyright (C) 2003 by Lincoln Stein This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.2 or, at your option, any later version of Perl 5 you may have available. perl v5.16.3 2014-06-10 Devel::Cycle(3)
All times are GMT -4. The time now is 09:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy