Sponsored Content
Top Forums Shell Programming and Scripting Removing carriage returns with sed Post 96434 by vino on Friday 20th of January 2006 04:29:27 AM
Old 01-20-2006
You need a KSH script or an awk script ?

Here is a ksh script.

Code:
[/tmp]$ cat steve.ksh 
#! /bin/ksh

while read line
do
        if [[ "$line" == *Group* ]] ; then

        GROUP=""
        ROLE=""
        USER=""
        GROUP=${line##*=}

        elif [[ "$line" == *Role* ]] ; then
        USER=""
        ROLE=${line#*=}
        ROLE=${ROLE%% *}

        elif [[ "$line" == *User* ]] ; then
        USER=${line##*=}
        fi ;

        [[ -n $GROUP && -n $ROLE && -n $USER ]] && echo "$GROUP,$ROLE,$USER"
done < text
[/tmp]$ ./steve.ksh 
G1,a1,Adam
G1,a1,Ben
G1,b1,Carl
G2,a1,Ben
G2,c1,Carl
G3,c1,Adam
[/tmp]$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed removing carriage return and newline

Hi, I'm not very familiar with unix shell. I want to replace the combination of two carriage returns and one newline with one carriage return and one newline. I think the best way to do this is to use sed. I tried something like this: sed -e "s#\#\#g" file.txt but it doesn't work. Thanx... (2 Replies)
Discussion started by: mored
2 Replies

2. Shell Programming and Scripting

spaces and carriage returns in 'here documents'

As the title suggests, i am having some trouble figuring out how to pass spaces and carriage returns to a 'here document' ie #!/bin/bash /usr/local/install_script.sh <<SCRIPT yes no <pass carriage retun here> yes no <pass a space and then a carriage return here> exit SCRIPT any... (0 Replies)
Discussion started by: hcclnoodles
0 Replies

3. Shell Programming and Scripting

Remove Carriage returns between strings in a field

Is there any way to remove carriage retuns between the records? We have input records separated by TABS and have carriage returns as below: 123 456 789 ABC "1952.00" 678 "abcdef ghik lmno" Above we... (10 Replies)
Discussion started by: acheepi
10 Replies

4. Shell Programming and Scripting

removing thousand of carriage returns using sed

I need to replace thousands of carriage returns/line breaks in a large xml file and with spaces. I hope to do so with a script, called, for example, "removeCRs." I would invoke this at the command line as ml5003$ sed -f /Users/ml5003/removeCRs oldFile > newFile The script, I presume, would... (4 Replies)
Discussion started by: ml5003
4 Replies

5. Shell Programming and Scripting

Replacing Carriage returns without loosing EOL

Hello, I have read a few threads on this subject and tried a few things out, but still come up short. There was one good example, then the last reply was something to the effect of 'Use Sed' & 'Read a book'... Well I read a bunch of online tutorials on sed, awk, tr, but still can't get the... (2 Replies)
Discussion started by: Majiktom
2 Replies

6. Shell Programming and Scripting

removing carriage returns in text file

Hi I have a text file that looks like this: A B C D E F G H I I want it to be reformatted to A;B;C; D;E;F; G;H;I; (4 Replies)
Discussion started by: coolnfunky
4 Replies

7. Emergency UNIX and Linux Support

Adding carriage returns to file using sed/awk

Hello, I need help adding carriage returns at specific intervals (say 692 characters) to a text file that's one continous string. I'm working in AIX5.3. Any quick help is appreciated. Thanks! (2 Replies)
Discussion started by: bd_joy
2 Replies

8. Shell Programming and Scripting

TR not removing carriage returns

I have a CSV with carriage returns in place of newlines. I am trying to use tr to remove them, but it isn't working. Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,4th Period,Arnold,Adam 2012-2013,First Semester,English 12,4th Period,Adams,Jim... (1 Reply)
Discussion started by: nextyoyoma
1 Replies

9. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

10. Shell Programming and Scripting

Remove carriage returns from awk output

I'm on Linux version 2.6.32-696.3.1.el6.x86_64, using the Ksh shell. I'm working with the input file: John Daggett, 341 King Road, Plymouth MA Alice Ford, 22 East Broadway, Richmond VA Orville Thomas, 11345 Oak Bridge Road, Tulsa OK Terry Kalkas, 402 Lans Road, Beaver Falls PA Eric Adams,... (2 Replies)
Discussion started by: prooney
2 Replies
CREATE 
ROLE(7) SQL Commands CREATE ROLE(7) NAME
CREATE ROLE - define a new database role SYNOPSIS
CREATE ROLE name [ [ WITH ] option [ ... ] ] where option can be: SUPERUSER | NOSUPERUSER | CREATEDB | NOCREATEDB | CREATEROLE | NOCREATEROLE | CREATEUSER | NOCREATEUSER | INHERIT | NOINHERIT | LOGIN | NOLOGIN | CONNECTION LIMIT connlimit | [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password' | VALID UNTIL 'timestamp' | IN ROLE rolename [, ...] | IN GROUP rolename [, ...] | ROLE rolename [, ...] | ADMIN rolename [, ...] | USER rolename [, ...] | SYSID uid DESCRIPTION
CREATE ROLE adds a new role to a PostgreSQL database cluster. A role is an entity that can own database objects and have database privi- leges; a role can be considered a ``user'', a ``group'', or both depending on how it is used. Refer to in the documentation and in the doc- umentation for information about managing users and authentication. You must have CREATEROLE privilege or be a database superuser to use this command. Note that roles are defined at the database cluster level, and so are valid in all databases in the cluster. PARAMETERS
name The name of the new role. SUPERUSER NOSUPERUSER These clauses determine whether the new role is a ``superuser'', who can override all access restrictions within the database. Superuser status is dangerous and should be used only when really needed. You must yourself be a superuser to create a new supe- ruser. If not specified, NOSUPERUSER is the default. CREATEDB NOCREATEDB These clauses define a role's ability to create databases. If CREATEDB is specified, the role being defined will be allowed to cre- ate new databases. Specifying NOCREATEDB will deny a role the ability to create databases. If not specified, NOCREATEDB is the default. CREATEROLE NOCREATEROLE These clauses determine whether a role will be permitted to create new roles (that is, execute CREATE ROLE). A role with CREATEROLE privilege can also alter and drop other roles. If not specified, NOCREATEROLE is the default. CREATEUSER NOCREATEUSER These clauses are an obsolete, but still accepted, spelling of SUPERUSER and NOSUPERUSER. Note that they are not equivalent to CRE- ATEROLE as one might naively expect! INHERIT NOINHERIT These clauses determine whether a role ``inherits'' the privileges of roles it is a member of. A role with the INHERIT attribute can automatically use whatever database privileges have been granted to all roles it is directly or indirectly a member of. Without INHERIT, membership in another role only grants the ability to SET ROLE to that other role; the privileges of the other role are only available after having done so. If not specified, INHERIT is the default. LOGIN NOLOGIN These clauses determine whether a role is allowed to log in; that is, whether the role can be given as the initial session autho- rization name during client connection. A role having the LOGIN attribute can be thought of as a user. Roles without this attribute are useful for managing database privileges, but are not users in the usual sense of the word. If not specified, NOLOGIN is the default, except when CREATE ROLE is invoked through its alternative spelling CREATE USER. CONNECTION LIMIT connlimit If role can log in, this specifies how many concurrent connections the role can make. -1 (the default) means no limit. PASSWORD password Sets the role's password. (A password is only of use for roles having the LOGIN attribute, but you can nonetheless define one for roles without it.) If you do not plan to use password authentication you can omit this option. If no password is specified, the password will be set to null and password authentication will always fail for that user. A null password can optionally be written explicitly as PASSWORD NULL. ENCRYPTED UNENCRYPTED These key words control whether the password is stored encrypted in the system catalogs. (If neither is specified, the default behavior is determined by the configuration parameter password_encryption.) If the presented password string is already in MD5-encrypted format, then it is stored encrypted as-is, regardless of whether ENCRYPTED or UNENCRYPTED is specified (since the sys- tem cannot decrypt the specified encrypted password string). This allows reloading of encrypted passwords during dump/restore. Note that older clients might lack support for the MD5 authentication mechanism that is needed to work with passwords that are stored encrypted. VALID UNTIL 'timestamp' The VALID UNTIL clause sets a date and time after which the role's password is no longer valid. If this clause is omitted the pass- word will be valid for all time. IN ROLE rolename The IN ROLE clause lists one or more existing roles to which the new role will be immediately added as a new member. (Note that there is no option to add the new role as an administrator; use a separate GRANT command to do that.) IN GROUP rolename IN GROUP is an obsolete spelling of IN ROLE. ROLE rolename The ROLE clause lists one or more existing roles which are automatically added as members of the new role. (This in effect makes the new role a ``group''.) ADMIN rolename The ADMIN clause is like ROLE, but the named roles are added to the new role WITH ADMIN OPTION, giving them the right to grant mem- bership in this role to others. USER rolename The USER clause is an obsolete spelling of the ROLE clause. SYSID uid The SYSID clause is ignored, but is accepted for backwards compatibility. NOTES
Use ALTER ROLE [alter_role(7)] to change the attributes of a role, and DROP ROLE [drop_role(7)] to remove a role. All the attributes speci- fied by CREATE ROLE can be modified by later ALTER ROLE commands. The preferred way to add and remove members of roles that are being used as groups is to use GRANT [grant(7)] and REVOKE [revoke(7)]. The VALID UNTIL clause defines an expiration time for a password only, not for the role per se. In particular, the expiration time is not enforced when logging in using a non-password-based authentication method. The INHERIT attribute governs inheritance of grantable privileges (that is, access privileges for database objects and role memberships). It does not apply to the special role attributes set by CREATE ROLE and ALTER ROLE. For example, being a member of a role with CREATEDB privilege does not immediately grant the ability to create databases, even if INHERIT is set; it would be necessary to become that role via SET ROLE [set_role(7)] before creating a database. The INHERIT attribute is the default for reasons of backwards compatibility: in prior releases of PostgreSQL, users always had access to all privileges of groups they were members of. However, NOINHERIT provides a closer match to the semantics specified in the SQL standard. Be careful with the CREATEROLE privilege. There is no concept of inheritance for the privileges of a CREATEROLE-role. That means that even if a role does not have a certain privilege but is allowed to create other roles, it can easily create another role with different privi- leges than its own (except for creating roles with superuser privileges). For example, if the role ``user'' has the CREATEROLE privilege but not the CREATEDB privilege, nonetheless it can create a new role with the CREATEDB privilege. Therefore, regard roles that have the CREATEROLE privilege as almost-superuser-roles. PostgreSQL includes a program createuser [createuser(1)] that has the same functionality as CREATE ROLE (in fact, it calls this command) but can be run from the command shell. The CONNECTION LIMIT option is only enforced approximately; if two new sessions start at about the same time when just one connection ``slot'' remains for the role, it is possible that both will fail. Also, the limit is never enforced for superusers. 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. The command createuser [createuser(1)], however, transmits the password encrypted. Also, psql [psql(1)] contains a command password that can be used to safely change the password later. EXAMPLES
Create a role that can log in, but don't give it a password: CREATE ROLE jonathan LOGIN; Create a role with a password: CREATE USER davide WITH PASSWORD 'jw8s0F4'; (CREATE USER is the same as CREATE ROLE except that it implies LOGIN.) Create a role with a password that is valid until the end of 2004. After one second has ticked in 2005, the password is no longer valid. CREATE ROLE miriam WITH LOGIN PASSWORD 'jw8s0F4' VALID UNTIL '2005-01-01'; Create a role that can create databases and manage roles: CREATE ROLE admin WITH CREATEDB CREATEROLE; COMPATIBILITY
The CREATE ROLE statement is in the SQL standard, but the standard only requires the syntax CREATE ROLE name [ WITH ADMIN rolename ] Multiple initial administrators, and all the other options of CREATE ROLE, are PostgreSQL extensions. The SQL standard defines the concepts of users and roles, but it regards them as distinct concepts and leaves all commands defining users to be specified by each database implementation. In PostgreSQL we have chosen to unify users and roles into a single kind of entity. Roles therefore have many more optional attributes than they do in the standard. The behavior specified by the SQL standard is most closely approximated by giving users the NOINHERIT attribute, while roles are given the INHERIT attribute. SEE ALSO
SET ROLE [set_role(7)], ALTER ROLE [alter_role(7)], DROP ROLE [drop_role(7)], GRANT [grant(7)], REVOKE [revoke(7)], createuser(1) SQL - Language Statements 2010-05-14 CREATE ROLE(7)
All times are GMT -4. The time now is 11:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy