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
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
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
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
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
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
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
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
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
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
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
LEARN ABOUT SUSE
xpsetcontext
XpSetContext(3Xp) XPRINT FUNCTIONS XpSetContext(3Xp)
NAME
XpSetContext - Sets or unsets a print context with the specified display connection to the X Print Server.
SYNOPSIS
cc [ flag... ] file... -lXp [ library... ]
#include <X11/extensions/Print.h>
void XpSetContext ( display, print_context )
Display *display;
XPContext print_context;
ARGUMENTS
display
Specifies a pointer to the Display structure; returned from XOpenDisplay.
print_context
A pre-existing print context on the same X Server.
DESCRIPTION
XpSetContext sets the print context for a display connection. All subsequent print operations that do not explicitly take a print context-
id (for example, XpStartJob) on display will use and act upon the print context set by this call, until the print context is unset or XpDe-
stroyContext is called. The print context can be set and used on multiple jobs, if not destroyed.
If print_context is None, XpSetContext will unset (disassociate) the print context previously associated with display. If there was no pre-
viously associated print context, no action is taken. The content of the formerly associated print context is not affected by this call,
and other display connections may continue to use the print context.
Since font capabilities can vary from printer to printer, XpSetContext may modify the list of available fonts (see XListFonts) on display,
and the actual set of usable fonts (see XLoadFont). A unique combination of fonts may be available from within a given print context; a
client should not assume that all the fonts available when no print context is set will be available when a print context is set.
When a print context is set on a display connection, the default behavior of ListFonts and ListFontsWithInfo is to list all of the fonts
normally associated with the X print server (i.e. fonts containing glyphs) as well as any internal printer fonts defined for the printer.
The xp-listfonts-modes attribute is provided so that applications can control the behavior of ListFonts and ListFontsWithInfo and is typi-
cally used to show just internal printer fonts. Using only internal printer fonts is useful for performance reasons; the glyphs associated
with the font are contained within the printer and do not have to be downloaded.
If the value of xp-listfonts-modes includes xp-list-glyph-fonts, ListFonts and ListFontsWithInfo will include all of the fonts available to
the server that have glyphs associated with them. If the value of xp-listfonts-modes includes xp-list-internal-printer-fonts, then List-
Fonts and ListFontsWithInfo will include all of the fonts defined as internal printer fonts.
When the print context is unset or XpDestroyContext is called, the available fonts on display revert back to what they were previously.
DIAGNOSTICS
XPBadContext A valid print context-id has not been set prior to making this call.
SEE ALSO
XpDestroyContext(3Xp), XpStartJob(3Xp)
X Version 11 libXp 1.0.0 XpSetContext(3Xp)