Sponsored Content
Full Discussion: Split column into rows
Top Forums UNIX for Beginners Questions & Answers Split column into rows Post 302991731 by saravananravim on Wednesday 15th of February 2017 10:25:39 PM
Old 02-15-2017
Split column into rows

Hi,

I have input dataset as below:

Code:
Cl.jenn,1051,ABCD
JEN.HEA,9740|1517|8119|2145,ZZZZ,REPEAT
Rich.Sm,
Ann.Car,3972|4051|1064|4323|4122|2394|2574|4507
Sta.for,7777,ABCD,UUUU
Sm.Ric,
Ch.LRD, 
Eh.ab,
Gr.sh,

Expected output:
-------------------
Code:
Cl.jenn,1051,ABCD
JEN.HEA,9740,ZZZZ,REPEAT
JEN.HEA,1517,ZZZZ,REPEAT
JEN.HEA,8119,ZZZZ,REPEAT
JEN.HEA,2145,ZZZZ,REPEAT
Rich.Sm,
Ann.Car,3972
Ann.Car,4051
Ann.Car,1064
Ann.Car,4323
Ann.Car,4122
Ann.Car,2394
Ann.Car,2574
Ann.Car,4507
Sta.for,7777,ABCD,UUUU
Sm.Ric,
Ch.LRD,
Eh.ab,
Gr.sh,

I am using below command to achieve this:
--------------------------------------------------
Code:
awk -F',' -v OFS=',' '{n=split($2,s,"|"); for(i=1;i<=n;i++) {$2=s[i];print}}' test.txt

Actual output is :
-------------------
Code:
Cl.jenn,1051,ABCD
JEN.HEA,9740,ZZZZ,REPEAT
JEN.HEA,1517,ZZZZ,REPEAT
JEN.HEA,8119,ZZZZ,REPEAT
JEN.HEA,2145,ZZZZ,REPEAT
Ann.Car,3972
Ann.Car,4051
Ann.Car,1064
Ann.Car,4323
Ann.Car,4122
Ann.Car,2394
Ann.Car,2574
Ann.Car,4507
Sta.for,7777,ABCD,UUUU
Ch.LRD,

Some records are filtered to display. Any suggestions pls???

Last edited by Don Cragun; 02-16-2017 at 12:01 AM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split rows

Hi I wanted to split rows based on the number of 1's present in 21st field(21st field is 40 length field) so I wrote the below awk code. However, the tool that I am using to invoke the command is not recognising the command. So, could you please help me to translate this command to sed? awk... (5 Replies)
Discussion started by: ahmedwaseem2000
5 Replies

2. Shell Programming and Scripting

Split rows

Hi all, I need a simple bin/sh script FILE1: ab1 gegege swgdeyedg ac2 jxjjxjxjxxjxjx ad3 ae4 xjxjxj zhzhzh ahahs af5 sjsjsjs ssjsjsjsj sjsjsj ag6 shshshshs sjjssj shhshshs myScript.sh has to return: ROW ab1 ROW ac2 ROW ad3 ROW ae4 In other words: "ROW " + the first world... (3 Replies)
Discussion started by: ric79
3 Replies

3. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

4. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

6. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

7. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

8. Shell Programming and Scripting

awk split columns after matching on rows and summing the last column

input: chr1 1 2 3 chr1 1 2 4 chr1 2 4 5 chr2 3 6 9 chr2 3 6 10 Code: awk '{a+=$4}END{for (i in a) print i,a}' input Output: chr112 7 chr236 19 chr124 5 Desired output: chr1 1 2 7 chr2 3 6 19 chr1 2 4 5 (1 Reply)
Discussion started by: jacobs.smith
1 Replies

9. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

10. UNIX for Beginners Questions & Answers

How to split one long column into multiple rows with 3 each ?

I have a large csv dataset like this : A value1 A value2 A value3 B value1 B value2 B value3 C value1 C value2 C value3 what I expected output is :A value1 value2 value3 B value1 value2 value3 C value1 value2 value3 I'm thinking of use like awk, columns , but haven't find a proper... (4 Replies)
Discussion started by: nengcheng
4 Replies
ldapmodify(1)							   User Commands						     ldapmodify(1)

NAME
ldapmodify, ldapadd - ldap entry addition and modification tools SYNOPSIS
ldapmodify [-a] [-c] [-r] [-n] [-v] [-F] [-b] [-A] [-q] [-H] [-?] [-E] [-J] [-Z] [-M] [-d debuglevel] [-D bindDN] [-j filename] [-J [:criticality]] [-B baseDN] [-V version] [-Y proxyDN] [-O hopLimit] [-i locale] [-k path] [-e errorFile] [-P path] [-N certificate] [-w passwd] [-o attributename=value] [-h ldaphost] [-W password] [-p ldapport] [-f file] [-l nb-ldap-connections] ldapadd [-c] [-n] [-v] [-F] [ [-b] [-A] [-q] [-H] [-?] [-E] [-J] [-Z] [-M]-d debuglevel] [-D bindDN] [-j filename] [-B baseDN] [-V version] [-Y proxyDN] [-O hopLimit] [-i locale] [-k path] [-e errorFile] [-P path] [-N certificate] [-w passwd] [-o attributename=value] [-h ldaphost] [-W password] [-p ldapport] [-f file] [-l nb-ldap-connections] DESCRIPTION
The ldapmodify utility opens a connection to an LDAP server, binds and modifies or adds entries. The entry information is read from stan- dard input or from file, specified using the -f option. The ldapadd utility is implemented as a hard link to the ldapmodify tool. When invoked as ldapadd, the -a (add new entry) option is turned on automatically. Both ldapadd and ldapmodify reject duplicate attribute-name/value pairs for the same entry. OPTIONS
The following options are supported: -a Adds new entries. The default for ldapmodify is to modify existing entries. If invoked as ldapadd, this option is always set. -A Non-ASCII mode: display non-ASCII values, in conjunction with the -v option. -b Handle binary files. The ldapmodify tool will scan every attribute value in the input to determine whether it is a valid file refer- ence. If the reference is valid, it will use the contents of the file as the attribute's value. This option is used to input binary data, such as a JPEG image, for an attribute. For example, the corresponding LDIF input would be: " jpegPhoto: /tmp/photo.jpg" The ldapmodify tool also supports the LDIF :< URL notation for directly including file contents. -B baseDN Specify the base DN when performing additions, usually in double quotes ("") for the shell. All entries will be placed under this suf- fix, thus providing bulk import functionality. -c Specifies continuous operation mode. Errors are reported, but ldapmodify and ldapadd continue with modifications. The default is to exit after reporting an error. -D bindDN Uses the distinguished name bindDN to bind to the directory. -d debuglevel Sets the LDAP debugging level. Useful levels of debugging for ldapmodify and ldapadd are: 1 Trace 2 Packets 4 Arguments 32 Filters 128 Access control To request more than one category of debugging information, add the masks. For example, to request trace and filter information, spec- ify a debuglevel of 33. -e errorFile Invalid update statements in the input will be copied to the errorFile for debugging. Use with the -c option to correct errors when processing large LDIF input. -E Ask server to expose (report) bind identity by means of authentication response control. -F Forces application of all changes regardless of the content of input lines that begin with replica:. By default, replica: lines are compared against the LDAP server host and port in use to decide whether a replog record should be applied. -f file Reads the entry modification information from file instead of from standard input. -? Display the usage help text that briefly describes all options. -H Display the usage help text that briefly describes all options. -h ldaphost Specifies an alternate host on which the LAPD server is running. -i locale Specify the character set to use for the -f LDIFfile or standard input. The default is the character set specified in the LANG environ- ment variable. You might choose to use this option to perform the conversion from the specified character set to UTF8, thus overriding the LANG setting. -j filename Specify a file containing the password for the bind DN or the password for the SSL client's key database. To protect the password, use this option in scripts and place the password in a secure file. This option is mutually exclusive of the -w and -W options. -J [:criticality[:value|::b64value|b64value|:fileurl]] Criticality is a boolean value (default is false). -k path Specify the path to a directory containing conversion routines. These routines are used if you want to specify a locale that is not supported by default by your directory server. This is for NLS support. -l nb-ldap-connections Specifies the number of LDAP connections that ldapadd or ldapmodify will open to process the modifications in the directory. The default is one connection. -M Manage smart referrals. When they are the target of the operation, modify the entry containing the referral instead of the entry obtained by following the referral. -n Previews modifications, but makes no changes to entries. Useful in conjunction with -v and -d for debugging. -N certificate Specify the certificate name to use for certificate-based client authentication. For example: -N "Directory-Cert". -o attributename=value For SASL mechanisms and other options such as security properties, mode of operation, authorization ID, authentication ID, and so forth. The different attribute names and their values are as follows: secProp="number" For defining SASL security properties. realm="value" Specifies SASL realm (default is realm=none). authzid="value" Specify the authorization ID name for SASL bind. authid="value" Specify the authentication ID for SASL bind. mech="value" Specifies the various SASL mechanisms. -O hopLimit Specify the maximum number of referral hops to follow while finding an entry to modify. By default, there is no limit. -p ldapport Specifies an alternate TCP port where the secure LDAP server is listening. -P path Specify the path and filename of the client's certificate database. For example: -P /home/uid/.netscape/cert7.db When using the command on the same host as the directory server, you can use the server's own certificate database. For example: -P installDir/lapd-serverID/alias/cert7.db Use the -P option alone to specify server authentication only. -r Replaces existing value with the specified value. This is the default for ldapmodify. When ldapadd is called, or if the -a option is specified, the -r option is ignored. -v Uses verbose mode, with diagnostics written to standard output. -V version Specify the LDAP protocol version number to be used for the delete operation, either 2 or 3. LDAP v3 is the default. Specify LDAP v2 when connecting to servers that do not support v3. -W password Specify the password for the client's key database given in the -P option. This option is required for certificate-based client authen- tication. Specifying password on the command line has security issues because the password can be seen by others on the system by means of the ps command. Use the -j instead to specify the password from the file. This option is mutually exclusive of -j. -w passwd Use passwd as the password for authentication to the directory. When you use -w passwd to specify the password to be used for authenti- cation, the password is visible to other users of the system by means of the ps command, in script files or in shell history. If you use either the ldapmodify command or the ldapadd command without this option, the command will prompt for the password and read it from standard in. When used without the -w option, the password will not be visible to other users. -Y proxyid Specify the proxy DN (proxied authorization id) to use for the modify operation, usually in double quotes ("") for the shell. -Z Specify that SSL be used to provide certificate-based client authentication. This option requires the -N and SSL password and any other of the SSL options needed to identify the certificate and the key database. EXIT STATUS
The following exit values are returned: 0 Successful completion. Non-zero An error occurred. A diagnostic message is written to standard error. EXAMPLES
The format of the content of file (or standard input if no -f option is specified) is illustrated in the following examples. Example 1: Modifying an Entry The file /tmp/entrymods contains the following modification instructions: dn: cn=Modify Me, o=XYZ, c=US changetype: modify replace: mail mail: modme@atlanta.xyz.com - add: title title: System Manager - add: jpegPhoto jpegPhoto:< file:///tmp/modme.jpeg - delete: description - The command: example% ldapmodify -r -f /tmp/entrymods modifies the Modify Me entry as follows: 1. The current value of the mail attribute is replaced with the value, modme@atlanta.xyz.com. 2. A title attribute with the value, System Manager, is added. 3. A jpegPhoto attribute is added, using the contents of the file, /tmp/modme.jpeg, as the attribute value. 4. The description attribute is removed. Example 2: Creating a New Entry The file, /tmp/newentry, contains the following information for creating a new entry: dn: cn=Ann Jones, o=XYZ, c=US objectClass: person cn: Ann Jones cn: Annie Jones sn: Jones title: Director of Research and Development mail: ajones@londonrd.xyz.us.com uid: ajones The command example% ldapadd -f /tmp/newentry adds a new entry for Ann Jones, using the information in the file. Example 3: Creating a New Entry on an IPv6 Server The file, /tmp/newentry, contains the following information for creating a new entry: on an IPv6 server. dn: cn=Ann Jones, o=XYZ, c=US objectClass: person cn: Ann Jones cn: Annie Jones sn: Jones title: Director of Research and Development mail: ajones@londonrd.xyz.us.com uid: ajones The command example% ldapadd -c -v -h '['fec0::111:a00:20ff:feaa:a364']':389 -D cn=Directory Manager -w secret -f /tmp/entry adds a new entry for Directory Manager, using the information in the file. Example 4: Deleting an Entry The file, /tmp/badentry, contains the following information about an entry to be deleted: dn: cn=Ann Jones, o=XYZ, c=US changetype: delete The command: example% ldapmodify -f /tmp/badentry removes Ann Jones' entry. ATTRIBUTES
See attributes(5) for a description of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |Stability Level |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
ldap(1), ldapdelete(1), ldaplist(1), ldapmodrdn(1), ldapsearch(1), ldapaddent(1M), ldap_cachemgr(1M), ldap_get_option(3LDAP), ldap_set_option(3LDAP), attributes(5) SunOS 5.10 15 Jan 2004 ldapmodify(1)
All times are GMT -4. The time now is 06:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy