shell scripts to grep dn in ldif file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell scripts to grep dn in ldif file
# 1  
Old 04-07-2008
shell scripts to grep dn in ldif file

Hi gurus out there,

1)I am using ksh, in solaris 10.
2)I have one ldif file, I need to output user DN with attributes=<some pattern> to a file.

Example:

dn: uid=joy,ou=People,o=abc.com,o=isp
nswmExtendedUserPrefs: meAutoSign=true
nswmExtendedUserPrefs: meSignature=Regards, Joy
mailUserStatus: inactive

dn: uid=John,ou=People,o=abc.com,o=isp
nswmExtendedUserPrefs: meAutoSign=true
nswmExtendedUserPrefs: meSignature=Thanks, John
mailUserStatus: inactive

I NEED to ouput an ldif with the attribute:
nswmExtendedUserPrefs: meSignature=Regards

Note that the pattern is "regards"

Anyone can give hint?

I am totally newbie, pls help.
Many many thanks!!!
# 2  
Old 04-07-2008
Code:
nawk 'BEGIN{FS="\n";RS=""}
{
if(index($3,"Regards")!=0)
print $0
}' filename

# 3  
Old 04-07-2008
Quote:
Originally Posted by summer_cherry
Code:
nawk 'BEGIN{FS="\n";RS=""}
{
if(index($3,"Regards")!=0)
print $0
}' filename

Thank you very much, may I know what is FS and RS? Sorry I am really a newbie.
# 4  
Old 04-07-2008
From awk man page :

Quote:
VARIABLES, RECORDS AND FIELDS
AWK variables are dynamic; they come into existence when they are first used.
Their values are either floating-point numbers or strings, or both, depending upon
how they are used. AWK also has one dimensional arrays; arrays with multiple
dimensions may be simulated. Several pre-defined variables are set as a program
runs; these are described as needed and summarized below.
Records
Normally, records are separated by newline characters. You can control how records
are separated by assigning values to the built-in variable RS. If RS is any single
character, that character separates records. Otherwise, RS is a regular expres-
sion. Text in the input that matches this regular expression separates the record.
However, in compatibility mode, only the first character of its string value is
used for separating records. If RS is set to the null string, then records are
separated by blank lines. When RS is set to the null string, the newline character
always acts as a field separator, in addition to whatever value FS may have.
Fields
As each input record is read, gawk splits the record into fields, using the value
of the FS variable as the field separator. If FS is a single character, fields are
separated by that character. If FS is the null string, then each individual char-
acter becomes a separate field. Otherwise, FS is expected to be a full regular
expression. In the special case that FS is a single space, fields are separated by
runs of spaces and/or tabs and/or newlines. (But see the section POSIX COMPATIBIL-
ITY, below). NOTE: The value of IGNORECASE (see below) also affects how fields are
split when FS is a regular expression, and how records are separated when RS is a
regular expression.

. . . . .

Built-in Variables
FS The input field separator, a space by default.
RS The input record separator, by default a newline.
Another version with awk :
Code:
$ cat ldif.sh
awk -v sign="${1:-Regards}" '
BEGIN {
   RS = "";
   signature_pattern = "meSignature=" sign
}
$0 ~ signature_pattern
    ' inputfile

$ ldif.sh
dn: uid=joy,ou=People,o=abc.com,o=isp
nswmExtendedUserPrefs: meAutoSign=true
nswmExtendedUserPrefs: meSignature=Regards, Joy
mailUserStatus: inactive
$ ldif.sh Thanks
dn: uid=John,ou=People,o=abc.com,o=isp
nswmExtendedUserPrefs: meAutoSign=true
nswmExtendedUserPrefs: meSignature=Thanks, John
mailUserStatus: inactive
$

Jean-Pierre
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Having a single Log file for all the shell scripts

Bash on RHEL 6.2 We have multiple shell scripts executed by cron jobs. Each Shell script has its own log files currently. Most of them have logs generated using spool command from Oracle RDBMS's sqlplus commmand. Sample: #!/bin/bash sqlplus -s scott/tiger << EOF spool... (5 Replies)
Discussion started by: kraljic
5 Replies

2. UNIX Desktop Questions & Answers

creating an executable file from shell scripts

Hi Friends, I have a shell script which does some operations etc, would it be possible to create an executable file out from this shell script? meaning the executable file is not editable, thus the source code will not be visible to other users for copyright reasons. Please help, thanks! (1 Reply)
Discussion started by: kokoro
1 Replies

3. Shell Programming and Scripting

Shell Scripts (Renaming file names with sequential numbers)

Hi there, Firstly, I have no experience with shell scripts so would really appreciate some help. I have the following shell script that is causing some problems: moveit() { && set -x if then DOUBLE_DELIVERY=$(grep... (6 Replies)
Discussion started by: thebeno
6 Replies

4. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

5. UNIX for Dummies Questions & Answers

Use of grep with multiple parameters in shell scripts

I am learning how to write shell scripts and have come across an issue. I'm trying to write a script that looks for a directory called public_html, and if it finds one, to print the number of lines that contain applet tags (containing '<applet') in all files that end in either .html or .htm that... (7 Replies)
Discussion started by: feverdream
7 Replies

6. UNIX for Dummies Questions & Answers

how to separate numbers and words from a file using shell scripts

Hi, How to separate numbers and words(with full alphabets) in a particular file and store it in two different files. Please help me out for this.Using shell scripting. :confused::confused: (1 Reply)
Discussion started by: kamakshi s
1 Replies

7. Shell Programming and Scripting

FTP is using shell scripts create ? for file

ftp -n -v <<EOF verbose open 3.57.40.79 user infodvlp pr0gram ascii lcd /home/a501420038/GLA/Success_Load/ cd /ftp/SrcFiles/csg/InstruAsia/ get AU_Success_Log.txt close quit EOF Please help on this, this gives the out put "AU_Success_Log.txt?" As question mark in the last what will... (1 Reply)
Discussion started by: a501420038
1 Replies

8. Shell Programming and Scripting

Need a simple file based utilty for shell scripts

Hello, I'm wondering if you may know of a simple file based UNIX utility that can be used to store and retrieve values on a flat file, let's say i have a file called "kru", i'd like to be able to specify a request like: while(....) if ; then kru.fld2 = $rec_cnt kru.fld3 =... (4 Replies)
Discussion started by: bobk544
4 Replies

9. Shell Programming and Scripting

Plz Help To convert xml file to text file using bourn shell scripts

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> <country_code>AK></country_code>... (0 Replies)
Discussion started by: ram2s2001
0 Replies

10. Shell Programming and Scripting

Converting Text File into XML using Unix Shell Scripts

Hi everyone, If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert a file into xml format using Unix shell scripts. The file has fields with each field having a certain number of bytes, but the fields are not delimited by anything... (10 Replies)
Discussion started by: Laud12345
10 Replies
Login or Register to Ask a Question