Sponsored Content
Top Forums Shell Programming and Scripting Please help in sorting record Post 302409491 by durden_tyler on Thursday 1st of April 2010 10:10:02 AM
Old 04-01-2010
Quote:
Originally Posted by learnbash
... how to sort my lines so All [a,A] shows first and [zZ] shows in last, i mean text orderwise on any column better on name basis.
...
Code:
$
$
$ cat f3
dn: uid=peter@example.com,ou=example-com...=example,dc=to
cn: Peter
sn: Norton
displayName: Peter Norton
dn: uid=ras@example.com,ou=example-com,o...=example,dc=to
cn: Ras
sn: Kam
displayName: Ras Kam
dn: uid=james@mi6.com,ou=example-com,ou=...=example,dc=to
cn: James
sn: Bond
displayName: James Bond
dn: uid=Bat@example.com,ou=example-com,o...=example,dc=to
cn: Bat
sn: Man
displayName: Bat Man
$
$ ##
$ perl -lne 'if (/^.*?uid=(.*?\@example.com).*$/){$x="email:$1"}
>            elsif(/^displayName: (.*?)$/ && $x){push @a, "$x Name: $1"; $x=""}
>            END {print foreach (sort @a)}' f3
email:Bat@example.com Name: Bat Man
email:peter@example.com Name: Peter Norton
email:ras@example.com Name: Ras Kam
$
$

tyler_durden

Looks like you asked for a case-insensitive sort. Here's an idea -

Code:
$
$
$ cat f3
dn: uid=peter@example.com,ou=example-com,ou=mail,dc=example,dc=to
cn: Peter
sn: Norton
displayName: Peter Norton

dn: uid=adam@example.com,ou=example-com,ou=mail,dc=example,dc=to
cn: adam
sn: smith
displayName: adam smith

dn: uid=james@mi6.com,ou=example-com,ou=mail,dc=example,dc=to
cn: James
sn: Bond
displayName: James Bond

dn: uid=Bat@example.com,ou=example-com,ou=mail,dc=example,dc=to
cn: Bat
sn: Man
displayName: Bat Man
$
$
$ perl -lne 'if (/^.*?uid=(.*?\@example.com).*$/){$x="email:$1"}
>            elsif(/^displayName: (.*?)$/ && $x){push @y, "$x Name: $1"; $x=""}
>            END {print foreach (sort {uc($a) cmp uc($b)} @y)}' f3
email:adam@example.com Name: adam smith
email:Bat@example.com Name: Bat Man
email:peter@example.com Name: Peter Norton
$
$

The prior script, when run on this file will put "Bat Man" before "adam smith" because ascii('B') < ascii('a').

HTH,
tyler_durden

Last edited by durden_tyler; 04-01-2010 at 11:26 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Print Full record and substring in that record

I have i got a requirement like below. I have input file which contains following fixed width records. 00000000000088500232007112007111 I need the full record and concatenated with ~ and characters from 1to 5 and concatenated with ~ and charactes from 10 to 15 The out put will be like... (1 Reply)
Discussion started by: ukatru
1 Replies

2. Shell Programming and Scripting

Sorting record

Hi all, Can any one help whether we can able to sort a record with delimiter plz ? (3 Replies)
Discussion started by: thelakbe
3 Replies

3. Shell Programming and Scripting

Sorting within a record using AWK

Hello, I have a file which has the following format: I have to do is sort individual records in the file based on the 4th field. Each record starts with "Module". Is there an easy way to do this using awk. I have tried piping output from awk to sort and also using "sort" inside awk but... (8 Replies)
Discussion started by: fifteate
8 Replies

4. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

5. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

6. Shell Programming and Scripting

Require original field position after sorting the values in a record

Dear Team, Can any body help me out to get the filed position of the records post sorting using AWK programming. Thanks in advance Example Input: StudentID col-1 col-2 col-3 col-4 1234 14 10 12 13 1235 10 11 12 13 1236 13 12 11 10 ... (3 Replies)
Discussion started by: Srinivasa Reddy
3 Replies

7. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

8. Shell Programming and Scripting

Sorting group of records and loading last record

Hi Everyone, I have below record set. File is fixed widht file 101newjersyus 20150110 101nboston us 20150103 102boston us 20140106 102boston us 20140103 I need to group record based on first 3 letters in our case(101 and 102) and sort last 8 digit in ascending order and print only... (4 Replies)
Discussion started by: patricjemmy6
4 Replies

9. Shell Programming and Scripting

Replace a string for every record after the 1st record

I have data coming in the below format for each record <?xml version="1.0" encoding="UTF-8" standalone="no"?><test_sox xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><testdetials>....</test_sox> <?xml version="1.0" encoding="UTF-8" standalone="no"?><test_sox... (8 Replies)
Discussion started by: dsravanam
8 Replies

10. Shell Programming and Scripting

Need code for updating second record to first record in shell scripting

Hi,, I have requirement that i need to get DISTINCT values from a table and if there are two records i need to update it to one record and then need to submit INSERT statements by using the updated value as a parameter. Here is the example follows.. SELECT DISTINCT ID FROM OFFER_GROUP WHERE... (1 Reply)
Discussion started by: Samah
1 Replies
CAFF(1) 						User Contributed Perl Documentation						   CAFF(1)

NAME
caff -- CA - Fire and Forget SYNOPSIS
caff [-eERS] [-m yes|ask-yes|ask-no|no] [-u yourkeyid] keyid [keyid ..] DESCRIPTION
CA Fire and Forget is a script that helps you in keysigning. It takes a list of keyids on the command line, fetches them from a keyserver and calls GnuPG so that you can sign it. It then mails each key to all its email addresses - only including the one UID that we send to in each mail, pruned from all but self sigs and sigs done by you. The mailed key is encrypted with itself as a means to verify that key belongs to the recipient. OPTIONS
-e, --export-old Export old signatures. Default is to ask the user for each old signature. -E, --no-export-old Do not export old signatures. Default is to ask the user for each old signature. -m, --mail yes|ask-yes|ask-no|no Whether to send mail after signing. Default is to ask, for each uid, with a default value of yes. -R, --no-download Do not retrieve the key to be signed from a keyserver. -S, --no-sign Do not sign the keys. -u yourkeyid, --local-user yourkeyid Select the key that is used for signing, in case you have more than one key. To sign with multiple keys at once, separate multiple keyids by comma. This option requires the key(s) to be defined through the keyid variable in the configuration file. --key-file file Import keys from file. Can be supplied more than once. --keys-from-gnupg file Try to import keys from your standard GnuPG keyrings. FILES
$HOME/.caffrc - configuration file $HOME/.caff/keys/yyyy-mm-dd/ - processed keys $HOME/.caff/gnupghome/ - caff's working dir for gpg $HOME/.caff/gnupghome/gpg.conf - gpg configuration useful options include use-agent, keyserver-options, default-cert-level, etc. CONFIGURATION FILE OPTIONS
The configuration file is a perl script that sets values in the hash %CONFIG. The file is generated when it does not exist. Example: $CONFIG{'owner'} = q{Peter Palfrader}; $CONFIG{'email'} = q{peter@palfrader.org}; $CONFIG{'keyid'} = [ qw{DE7AAF6E94C09C7F 62AF4031C82E0039} ]; Required basic settings owner [string] Your name. REQUIRED. email [string] Your email address, used in From: lines. REQUIRED. keyid [list of keyids] A list of your keys. This is used to determine which signatures to keep in the pruning step. If you select a key using -u it has to be in this list. REQUIRED. General settings caffhome [string] Base directory for the files caff stores. Default: $HOME/.caff/. GnuPG settings gpg [string] Path to the GnuPG binary. Default: gpg. gpg-sign [string] Path to the GnuPG binary which is used to sign keys. Default: what gpg is set to. gpg-delsig [string] Path to the GnuPG binary which is used to split off signatures. This was needed while the upstream GnuPG was not fixed. Default: what gpg is set to. secret-keyring [string] Path to your secret keyring. Default: $HOME/.gnupg/secring.gpg. also-encrypt-to [keyid, or list of keyids] Additional keyids to encrypt messages to. Default: none. gpg-sign-args [string] Additional commands to pass to gpg after the "sign" command. Default: none. Keyserver settings keyserver [string] Keyserver to download keys from. Default: pool.sks-keyservers.net. no-download [boolean] If true, then skip the step of fetching keys from the keyserver. Default: 0. key-files [list of files] A list of files containing keys to be imported. Signing settings no-sign [boolean] If true, then skip the signing step. Default: 0. ask-sign [boolean] If true, then pause before continuing to the signing step. This is useful for offline signing. Default: 0. export-sig-age [seconds] Don't export UIDs by default, on which your latest signature is older than this age. Default: 24*60*60 (i.e. one day). local-user [keyid, or list of keyids] Select the key that is used for signing, in case you have more than one key. With multiple keyids, sign with each key in turn. Mail settings mail [boolean] Whether to send mails. This is a quad-option, with which you can set the behaviour: yes always sends, no never sends; ask-yes and ask- no asks, for each uid, with according defaults for the question. Default: ask-yes. In any case, the messages are also written to $CONFIG{'caffhome'}/keys/ mail-template [string] Email template which is used as the body text for the email sent out instead of the default text if specified. The following perl variables can be used in the template: {owner} [string] Your name as specified in the owner setting. {key} [string] The keyid of the key you signed. {@uids} [array] The UIDs for which signatures are included in the mail. reply-to [string] Add a Reply-To: header to messages sent. Default: none. bcc [string] Address to send blind carbon copies to when sending mail. Default: none. mailer-send [array] Parameters to pass to Mail::Mailer. This could for example be $CONFIG{'mailer-send'} = [ 'smtp', Server => 'mail.server', Auth => ['user', 'pass'] ]; to use the perl SMTP client or $CONFIG{'mailer-send'} = [ 'sendmail', '-o8' ]; to pass arguments to the sendmail program. For more information run "perldoc Mail::Mailer". Setting this option is strongly discouraged. Fix your local MTA instead. Default: none. AUTHORS
Peter Palfrader <peter@palfrader.org> Christoph Berg <cb@df7cb.de> WEBSITE
http://pgp-tools.alioth.debian.org/ SEE ALSO
gpg(1), pgp-clean(1), /usr/share/doc/signing-party/caff/ perl v5.12.4 2011-11-01 CAFF(1)
All times are GMT -4. The time now is 09:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy