Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Need advise/tip if there is more efficient way of doing this cut/paste/awk after changing a field Post 303044636 by MadeInGermany on Friday 28th of February 2020 12:21:43 PM
Old 02-28-2020
A more detailed explanation follows.
The main awk code runs for each input line.
!a[$0]++ is ultra-condensed, quick and dirty.
A bit more explicit is !($0 in A) { A[$0]; print }:
If not $0 in array A (A[$0] not defined) then define A[$0] (no A[$0]=value needed here) and print $0.
The array A is associative (string-addressed). So if the same $0 will occur in another input line it will see a defined A[$0] and won't print.
If there is a pre-condition and no { action code } following then the default for a true condition is { print }, and print without arguments defaults to print $0.

Now to the quick and dirty !A[$0]++:
Define A[$0] with value 0 if undefined, if the negated value is non-zero (true) then default-print. Also post-increment A[$0].
If the same $0 will occur then the A[$0] value will be 1, negated 0 (false), won't print, but post-incremented.
If the same $0 will occur then the A[$0] value will be 2, negated 0 (false), won't print, but post-incremented.
...
This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cut and paste columns using awk

Hi, Let's say that I have a file called table, I know that if I need to see a the second column for exampls I use: awk ' {print $2}' table.txt Is there anyway to use awk to actually cut a column and put it somewhere else in the table?:confused: (8 Replies)
Discussion started by: cosmologist
8 Replies

2. Shell Programming and Scripting

cut and paste using awk

Hi i need a favour i have a file which has some trillions of records. The file is like this 11111000000000192831840914000000000000000000000000000 45789899090000000000000000011111111111111111111111111 I want to cut specific postions in each line like cut1-3 and assisgn it to a variable and... (5 Replies)
Discussion started by: richa2.m
5 Replies

3. Shell Programming and Scripting

cut and paste?

hi, I have a file with content like this for an employee: EmployeeID 101 Day_type, day vacation,1/2/2009 sick day, 3/2/2009 personal day, 4/5/2009 jury duty day, 5/5/2009 how do I make the result to show: EmployeeID,Day_type,day 101,vacation,1/2/2009 101,sick day,... (6 Replies)
Discussion started by: jbchen
6 Replies

4. UNIX for Advanced & Expert Users

Printing Field with Delimiter in AWK/cut

Hello, I had posted earlier about printing fields using AWK, but now I have a slightly different problem. I have text files in the format: 1*2,3,4,5 and wish to print the first, third, and fifth fields, including the asterisk and commas. In other words, after filtering it should look... (1 Reply)
Discussion started by: Jahn
1 Replies

5. Shell Programming and Scripting

cut and paste

Hi, Need a help with shell script. I have to search for a string in one of the file, if match found, copy the line to a new file and delete the line from the exisiting file. eg: 83510000000000063800000.1800000.1600000.1600000.2400000.1800000.2000000.21... (6 Replies)
Discussion started by: gpaulose
6 Replies

6. Shell Programming and Scripting

awk,cut fields by change field format

Hi Everyone, # cat 1.txt 1321631,77770132976455,19,20091001011859,20091001011907 1321631,77770132976455,19,20091001011859,20091001011907 1321631,77770132976455,19,20091001011859,20091001011907 # cat 1.txt | awk -F, '{OFS=",";print $1,$3,$4,$5}' 1321631,19,20091001011859,20091001011907... (7 Replies)
Discussion started by: jimmy_y
7 Replies

7. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

8. UNIX for Advanced & Expert Users

Which cut command is more efficient?

Hi, I've got a query regarding which of the following is more efficient & why - cat <filename>|cut -d'*' -f2- > <newfilename> or cut -d'*' -f2- <filename> > <newfilename> Thanks. (17 Replies)
Discussion started by: sumoka
17 Replies

9. Shell Programming and Scripting

need help with cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (3 Replies)
Discussion started by: drew211
3 Replies

10. Shell Programming and Scripting

how to cut the last field without using awk

i have file as with the below content aaa.bbb.cc.dd aaa.fff.bb yyyyy.rrrrr.ggggg.iii wwww.w.r.ty i want the o/p as below dd bb iii ty but i dont want to use awk. is there any other way to do this ? (5 Replies)
Discussion started by: anandgodse
5 Replies
PPIx::Regexp::Token::Modifier(3pm)			User Contributed Perl Documentation			PPIx::Regexp::Token::Modifier(3pm)

NAME
PPIx::Regexp::Token::Modifier - Represent modifiers. SYNOPSIS
use PPIx::Regexp::Dumper; PPIx::Regexp::Dumper->new( 'qr{foo}smx' ) ->print(); The trailing "smx" will be represented by this class. This class also represents the whole of things like "(?ismx)". But the modifiers in something like "(?i:foo)" are represented by a PPIx::Regexp::Token::GroupType::Modifier. INHERITANCE
"PPIx::Regexp::Token::Modifier" is a PPIx::Regexp::Token. "PPIx::Regexp::Token::Modifier" is the parent of PPIx::Regexp::Token::GroupType::Modifier. DESCRIPTION
This class represents modifier characters at the end of the regular expression. For example, in "qr{foo}smx" this class would represent the terminal "smx". The "a", "aa", "d", "l", and "u" modifiers The "a", "aa", "d", "l", and "u" modifiers, introduced starting in Perl 5.13.6, are used to force either Unicode pattern semantics ("u"), locale semantics ("l") default semantics ("d" the traditional Perl semantics, which can also mean 'dual' since it means Unicode if the string's UTF-8 bit is on, and locale if the UTF-8 bit is off), or restricted default semantics ("a"). These are mutually exclusive, and only one can be asserted at a time. Asserting any of these overrides the inherited value of any of the others. The "asserted()" method reports as asserted the last one it sees, or none of them if it has seen none. For example, given "PPIx::Regexp::Token::Modifier" $elem representing the invalid regular expression fragment "(?dul)", "$elem->asserted( 'l' )" would return true, but "$elem->asserted( 'u' )" would return false. Note that "$elem->negated( 'u' )" would also return false, since "u" is not explicitly negated. If $elem represented regular expression fragment "(?i)", "$elem->asserted( 'd' )" would return false, since even though "d" represents the default behavior it is not explicitly asserted. The caret ("^") modifier Calling "^" a modifier is a bit of a misnomer. The "(?^...)" construction was introduced in Perl 5.13.6, to prevent the inheritance of modifiers. The documentation calls the caret a shorthand equivalent for "d-imsx", and that it the way this class handles it. For example, given "PPIx::Regexp::Token::Modifier" $elem representing regular expression fragment "(?^i)", "$elem->asserted( 'd' )" would return true, since in the absence of an explicit "l" or "u" this class considers the "^" to explicitly assert "d". Note that if this is retracted before Perl 5.14 is released, this support will disappear. See "NOTICE" in PPIx::Regexp for some explanation. METHODS
This class provides the following public methods. Methods not documented here are private, and unsupported in the sense that the author reserves the right to change or remove them without notice. asserts $token->asserts( 'i' ) and print "token asserts i"; foreach ( $token->asserts() ) { print "token asserts $_ " } This method returns true if the token explicitly asserts the given modifier. The example would return true for the modifier in "(?i:foo)", but false for "(?-i:foo)". If called without an argument, or with an undef argument, all modifiers explicitly asserted by this token are returned. match_semantics my $sem = $token->match_semantics(); defined $sem or $sem = 'undefined'; print "This token has $sem match semantics "; This method returns the match semantics asserted by the token, as one of the strings 'a', 'aa', 'd', 'l', or 'u'. If no explicit match semantics are asserted, this method returns "undef". modifiers my %mods = $token->modifiers(); Returns all modifiers asserted or negated by this token, and the values set (true for asserted, false for negated). If called in scalar context, returns a reference to a hash containing the values. negates $token->negates( 'i' ) and print "token negates i "; foreach ( $token->negates() ) { print "token negates $_ " } This method returns true if the token explicitly negates the given modifier. The example would return true for the modifier in "(?-i:foo)", but false for "(?i:foo)". If called without an argument, or with an undef argument, all modifiers explicitly negated by this token are returned. SUPPORT
Support is by the author. Please file bug reports at <http://rt.cpan.org>, or in electronic mail to the author. AUTHOR
Thomas R. Wyant, III wyant at cpan dot org COPYRIGHT AND LICENSE
Copyright (C) 2009-2012 by Thomas R. Wyant, III This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. perl v5.14.2 2012-06-06 PPIx::Regexp::Token::Modifier(3pm)
All times are GMT -4. The time now is 02:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy