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
D:(1)								   User Commands							     D:(1)

NAME
D: - find defects in conditinal C code SYNOPSIS
undertaker [OPTIONS] <file..> DESCRIPTION
I: undertaker v1.1+179-2bb9f3f-dirty `undertaker' analyzes conditional C code with #ifdefs. OPTIONS
-V print version information -v increase the log level (more verbose) -q decrease the log level (less verbose) -m specify the model(s) (directory or file) -M specify the main model -w specify a whitelist -b specify a worklist (batch mode) -t specify count of parallel processes -I add an include path for #include directives -j specify the jobs which should be done dead dead/undead file analysis (default) coverage coverage file analysis cpppc CPP Preconditions for whole file blockpc: Block precondition (format: <file>:<line> <column>) symbolpc Symbol precondition (format <symbol>) checkexpr Find a configuration that satisfies expression interesting Find related items (negated items are not in the model) Coverage Options: -O: specify the output mode of generated configurations kconfig generated partial kconfig configuration (default) stdout print on stdout the found configurations cpp print on stdout cpp -D command line arguments exec:cmd pipe file for every configuration to cmd model print all options which are in the configuration space all dump every assigned symbol (both items and code blocks) -C: specify coverage algorithm simple - relative simple and fast algorithm (default) min - slow but generates less configuration sets Specifying Files: You can specify one or many files (the format is according to the job (-j) which should be done. If you specify - as file, under- taker will load models and whitelist and read files from stdin (interactive). please specify a file to scan or a worklist `undertaker' analyzes conditional C code with #ifdefs. Usage: undertaker [OPTIONS] <file..> -V print version information -v increase the log level (more verbose) -q decrease the log level (less verbose) -m specify the model(s) (directory or file) -M specify the main model -w specify a whitelist -b specify a worklist (batch mode) -t specify count of parallel processes -I add an include path for #include directives -j specify the jobs which should be done dead dead/undead file analysis (default) coverage coverage file analysis cpppc CPP Preconditions for whole file blockpc: Block precondition (format: <file>:<line> <column>) symbolpc Symbol precondition (format <symbol>) checkexpr Find a configuration that satisfies expression interesting Find related items (negated items are not in the model) Coverage Options: -O: specify the output mode of generated configurations kconfig generated partial kconfig configuration (default) stdout print on stdout the found configurations cpp print on stdout cpp -D command line arguments exec:cmd pipe file for every configuration to cmd model print all options which are in the configuration space all dump every assigned symbol (both items and code blocks) -C: specify coverage algorithm simple - relative simple and fast algorithm (default) min - slow but generates less configuration sets Specifying Files: You can specify one or many files (the format is according to the job (-j) which should be done. If you specify - as file, under- taker will load models and whitelist and read files from stdin (interactive). AUTHOR
Written by the VAMOS team <URL:http://vamos.informatik.uni-erlangen.de> REPORTING BUGS
Report bugs to <vamos-dev@i4.informatik.uni-erlangen.de>. SEE ALSO
undertaker(1) undertaker-kconfigdump(1), undertaker-linux-tree(1). D
: undertaker v1.1+179-2bb9f3f-dirty December 2011 D:(1)
All times are GMT -4. The time now is 10:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy