Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminiate the white spaces - Unix script

Status
Not open for further replies.

nitincm

Technical User
Sep 10, 2003
22
0
0
US
Hi guys,

I hv to eliminiate the white spaces from following entry.
for eg: uid=AdminCFT1, ou=adminaccount, o=xyz, dc=com
In above entry space is their after , (comma)
[between uid= upto =com ]

First I hv to find which dn: entry has space & if space is their them remove that space.I got 65000 entries.

=====================================
Entry examples:
=====================================
dn: uid=AdminCFT1, ou=adminaccount, o=xyz, dc=com
objectClass: AdminAccount
objectClass: simpleSecurityObject
objectClass: top
userPassword: {SSHA}m0//7Z5RH0CSP1UUecezLR5D8+jZAEspa0ZbCQ==
uid: ADMINCFT1

dn: uid=AdminSCPM1, ou=adminaccount, o=xyz, dc=com
objectClass: top
objectClass: simpleSecurityObject
objectClass: AdminAccount
uid: ADMINSCPM1
userPassword: {CRYPT}9IWaaVNDcr1j.

dn: uid=AdminCSC1, ou=adminaccount, o=xyz, dc=com
objectClass: simpleSecurityObject
objectClass: top
objectClass: AdminAccount
uid: ADMINCSC1
owner: uid=A611753,ou=account,o=xyz,dc=com
owner: uid=ZZ36784,ou=account,o=xyz,dc=com
userPassword: {SSHA}5JcDKtBrz476fuwvRyk9lTrv0b/mVNRIIlsPcg==

dn: uid=ownertoolkit,ou=adminaccount,o=xyz,dc=com
objectClass: top
objectClass: simpleSecurityObject
objectClass: AdminAccount
userPassword: {SSHA}TEKGInbR4dU50eWvZg0GBxO4DGJVMxAfYmcvPw==
uid: OWNERTOOLKIT
 
so bascially what you want to do is to remove the space after the comma, right? And you want to keep the comma, just remove the space. And it appears that the dn lines are the only places where there is a comma.

Try this:
sed -e 's/, /,/g' original.txt > space_removed.txt
 
Thanks for u r prompt responce... but not working...tried..I got same output as input..

comma is at other places too but I am concern about only dn: entry..
 
in the red section below, did you put a space after the comma?

sed -e 's/, /,/g' original.txt > space_removed.txt
 
No I didn't I used
#sed -e 's/,/,/g' /tmp/fullrecord >/tmp/corr
 
that's why your output was the same as the input.
 
Thanx man...It worked.

Can u explained me the syntax...if possible?
 
Can u suggest me, If I would like to remove space before comma and after comma in whole file.?
Can I use like this?

#sed -e "s/ ,/, //,/g" /tmp/fullfile

thanks for u r helping hand...I m new to scripting...so..
 
nitincm,

To remove the spaces before and after the comma in a file, use the following command:

sed -e 's/, /,/g;s/ ,/,/g' filename

or

sed -e 's/, /,/g' -e 's/ ,/,/g' filename

Thanks,

John
[afro]

 
syntax:

sed -e 's/, /,/g' original.txt > space_removed.txt

sed is the command
-e indicates to sed that instructions follow.
' is required before the instructions and after the instructions
s means search on what follows the /
/ indicates it's the beginning of the search pattern
, (followed by a space) says search for patterns of a comma follwed by a space
/ tells sed what to search for has been defined and sets up the replace
, tells sed to replace the ,space with just a comma.
/ closes the replace pattern
g means global
' closes the instructions
first file is the file to perform the instructions on
> second_file says to output the results to that file.
 
How I can just identify space before comma or after comma?
If space is their then I hv to deplay that line.
 
egrep '([ ]+,|,[ ]+)' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top