Sponsored Content
Top Forums Shell Programming and Scripting awk filter by columns of file csv Post 302858517 by RudiC on Monday 30th of September 2013 03:59:22 PM
Old 09-30-2013
Short cut processing of
Code:
if (a[$2]++ > 1 && a[$3]++ > 1 && a[$4]++ > 1

will circumvent the evaluation of a[$3] and/or a[$4] should either of the earlier comparisons fail. Try a modification of your script:
Code:
awk     'BEGIN          {FS=OFS=";"}
                        {a[$2]++;a[$3]++;a[$4]++
                         if (a[$2] > 1 && a[$3] > 1 && a[$4] > 1){print $0";ROLE 3";}
                        }
        ' file
ULLNP;78;17/09/2013;OL;ROLE 3
NPNG;14;12/09/2013;AperturaTK;ROLE 3
NP;14;12/09/2013;Controllo;ROLE 3

which is - funny enough - identical to Don Cragun's result. Sorting will in almost any case modify that result, as the order in which the lines fulfill the conditions will be scrambled.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

validation of data using filter (awk or other that works...) in csv files

Hello People I have the following file.csv: date,string,float,number,boolean 20080303,abc,1.5,123,Y 20080304,abc,1.2,345,N 20080229,nvh,1.4,098,Y 20080319,ugy,1.9,586,N 20080315,gyh,2.4,345,Y 20080316,erf,3.1,932,N I need to filter the date field where I have a data bigger than I... (1 Reply)
Discussion started by: Rafael.Buria
1 Replies

2. Shell Programming and Scripting

AWK : Add columns in the end of csv file

Hi everybody, I need some help please I have a csv file named masterFile1.csv header1,header2,header3 value1,value2,value3 value4,value5,value6 I am trying to add new columns in the end of the csv to have a new csv file named masterFile2.csv like this :... (3 Replies)
Discussion started by: villebonnais
3 Replies

3. UNIX for Advanced & Expert Users

Help in Deleting columns and Renaming Mutliple columns in a .Csv File

Hi All, i have a .Csv file in the below format startTime, endTime, delta, gName, rName, rNumber, m2239max, m2239min, m2239avg, m100016509avg, m100019240max, metric3min, m100019240avg, propValues 11-Mar-2012 00:00:00, 11-Mar-2012 00:05:00, 300.0, vma3550a, a-1_CPU Index<1>, 200237463, 0.0,... (9 Replies)
Discussion started by: mahi_mayu069
9 Replies

4. Shell Programming and Scripting

awk filter by occurence of at least two columns

Hi, Using AWK script I want to pick those rows that has AT LEAST TWO columns EACH has a count >=3. i.e. two conditions: at least two columns, each of which has a count at least 3. There must be a simple way to do this job, but could not figure it out by myself. Input file (thousand of... (3 Replies)
Discussion started by: yifangt
3 Replies

5. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

Need help with awk statement to break nth column in csv file into 3 separate columns

Hello Members, I have a csv file in the format below. Need help with awk statement to break nth column into 3 separate columns and export the changes to new file. input file --> file.csv cat file.csv|less "product/fruit/mango","location/asia/india","type/alphonso" need output in... (2 Replies)
Discussion started by: awk-admirer
2 Replies

7. Linux

Filter a .CSV file based on the 5th column values

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , comma","string with or, without commas","string 1","USD","12","70%","08/01/2013",""... (2 Replies)
Discussion started by: dhruuv369
2 Replies

8. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

9. Shell Programming and Scripting

Add 8 columns at the end of .csv file using awk

Hello all, I have a .csv file of 16 columns consists of bunch of numbers. 6.45E+01 1.17E+01 8.10E+04 8.21E+01 8.50E+00 1.20E+01 1.02E+01 1.88E+01 1.86E+04 3.53E+03 1.09E+07 3.82E+04 2.09E+03 3.57E+03 2.98E+03 3.93E+03 6.34E+01 3.23E+01 9.24E+04 ... (5 Replies)
Discussion started by: Zam_1234
5 Replies

10. Shell Programming and Scripting

Filter using awk in CSV files

Hello Gentlemen, Finding difficulties to play with my Input files:confused: . Your guidance will certainly help as always. After converting to csv file from XLSM file, I am getting some extra ""(double quote) characters which I want to terminate inside shell script and process it further. ... (6 Replies)
Discussion started by: pradyumnajpn10
6 Replies
ALTER 
ROLE(7) PostgreSQL 9.2.7 Documentation ALTER ROLE(7) NAME
ALTER_ROLE - change a database role SYNOPSIS
ALTER ROLE name [ [ WITH ] option [ ... ] ] where option can be: SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE | CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | REPLICATION | NOREPLICATION | CONNECTION LIMIT connlimit | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | VALID UNTIL 'timestamp' ALTER ROLE name RENAME TO new_name ALTER ROLE name [ IN DATABASE database_name ] SET configuration_parameter { TO | = } { value | DEFAULT } ALTER ROLE name [ IN DATABASE database_name ] SET configuration_parameter FROM CURRENT ALTER ROLE name [ IN DATABASE database_name ] RESET configuration_parameter ALTER ROLE name [ IN DATABASE database_name ] RESET ALL DESCRIPTION
ALTER ROLE changes the attributes of a PostgreSQL role. The first variant of this command listed in the synopsis can change many of the role attributes that can be specified in CREATE ROLE (CREATE_ROLE(7)). (All the possible attributes are covered, except that there are no options for adding or removing memberships; use GRANT(7) and REVOKE(7) for that.) Attributes not mentioned in the command retain their previous settings. Database superusers can change any of these settings for any role. Roles having CREATEROLE privilege can change any of these settings, but only for non-superuser and non-replication roles. Ordinary roles can only change their own password. The second variant changes the name of the role. Database superusers can rename any role. Roles having CREATEROLE privilege can rename non-superuser roles. The current session user cannot be renamed. (Connect as a different user if you need to do that.) Because MD5-encrypted passwords use the role name as cryptographic salt, renaming a role clears its password if the password is MD5-encrypted. The remaining variants change a role's session default for a configuration variable, either for all databases or, when the IN DATABASE clause is specified, only for sessions in the named database. Whenever the role subsequently starts a new session, the specified value becomes the session default, overriding whatever setting is present in postgresql.conf or has been received from the postgres command line. This only happens at login time; executing SET ROLE (SET_ROLE(7)) or SET SESSION AUTHORIZATION (SET_SESSION_AUTHORIZATION(7)) does not cause new configuration values to be set. Settings set for all databases are overridden by database-specific settings attached to a role. Superusers can change anyone's session defaults. Roles having CREATEROLE privilege can change defaults for non-superuser roles. Ordinary roles can only set defaults for themselves. Certain configuration variables cannot be set this way, or can only be set if a superuser issues the command. PARAMETERS
name The name of the role whose attributes are to be altered. SUPERUSER, NOSUPERUSER, CREATEDB, NOCREATEDB, CREATEROLE, NOCREATEROLE, CREATEUSER, NOCREATEUSER, INHERIT, NOINHERIT, LOGIN, NOLOGIN, REPLICATION, NOREPLICATION, CONNECTION LIMIT connlimit, PASSWORD password, ENCRYPTED, UNENCRYPTED, VALID UNTIL 'timestamp' These clauses alter attributes originally set by CREATE ROLE (CREATE_ROLE(7)). For more information, see the CREATE ROLE reference page. new_name The new name of the role. database_name The name of the database the configuration variable should be set in. configuration_parameter, value Set this role's session default for the specified configuration parameter to the given value. If value is DEFAULT or, equivalently, RESET is used, the role-specific variable setting is removed, so the role will inherit the system-wide default setting in new sessions. Use RESET ALL to clear all role-specific settings. SET FROM CURRENT saves the session's current value of the parameter as the role-specific value. If IN DATABASE is specified, the configuration parameter is set or removed for the given role and database only. Role-specific variable settings take effect only at login; SET ROLE (SET_ROLE(7)) and SET SESSION AUTHORIZATION (SET_SESSION_AUTHORIZATION(7)) do not process role-specific variable settings. See SET(7) and Chapter 18, Server Configuration, in the documentation for more information about allowed parameter names and values. NOTES
Use CREATE ROLE (CREATE_ROLE(7)) to add new roles, and DROP ROLE (DROP_ROLE(7)) to remove a role. ALTER ROLE cannot change a role's memberships. Use GRANT(7) and REVOKE(7) to do that. Caution must be exercised when specifying an unencrypted password with this command. The password will be transmitted to the server in cleartext, and it might also be logged in the client's command history or the server log. psql(1) contains a command password that can be used to change a role's password without exposing the cleartext password. It is also possible to tie a session default to a specific database rather than to a role; see ALTER DATABASE (ALTER_DATABASE(7)). If there is a conflict, database-role-specific settings override role-specific ones, which in turn override database-specific ones. EXAMPLES
Change a role's password: ALTER ROLE davide WITH PASSWORD 'hu8jmn3'; Remove a role's password: ALTER ROLE davide WITH PASSWORD NULL; Change a password expiration date, specifying that the password should expire at midday on 4th May 2015 using the time zone which is one hour ahead of UTC: ALTER ROLE chris VALID UNTIL 'May 4 12:00:00 2015 +1'; Make a password valid forever: ALTER ROLE fred VALID UNTIL 'infinity'; Give a role the ability to create other roles and new databases: ALTER ROLE miriam CREATEROLE CREATEDB; Give a role a non-default setting of the maintenance_work_mem parameter: ALTER ROLE worker_bee SET maintenance_work_mem = 100000; Give a role a non-default, database-specific setting of the client_min_messages parameter: ALTER ROLE fred IN DATABASE devel SET client_min_messages = DEBUG; COMPATIBILITY
The ALTER ROLE statement is a PostgreSQL extension. SEE ALSO
CREATE ROLE (CREATE_ROLE(7)), DROP ROLE (DROP_ROLE(7)), SET(7) PostgreSQL 9.2.7 2014-02-17 ALTER ROLE(7)
All times are GMT -4. The time now is 09:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy