Replace a line start with single space
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Replace a line start with single space
I have following lines in ldap format
cn=some, ou=some, ou=s
ome, o=org
cn=somethingelse, ou=same, o
u=same, o=org
cn=same, ou=some,ou=something,
o=org
I want to do couple of things
1, I want to remove a line that start with space. I'm looking for following output
cn=some, ou=some, ou=s
cn=somethingelse, ou=same, o
cn=same, ou=some,ou=something,
2, I want to join a line start with space to previous line and output should as below
cn=some, ou=some, ou=some,o=org
cn=somethingelse, ou=same, o=org
cn=same, ou=some,ou=something, o=org
Could some one help to do this with regular expression. I need to lot of export, cleans and import the data to ldap.
Thanks
cn=some, ou=some, ou=s
ome, o=org
cn=somethingelse, ou=same, o
u=same, o=org
cn=same, ou=some,ou=something,
o=org
I want to do couple of things
1, I want to remove a line that start with space. I'm looking for following output
cn=some, ou=some, ou=s
cn=somethingelse, ou=same, o
cn=same, ou=some,ou=something,
2, I want to join a line start with space to previous line and output should as below
cn=some, ou=some, ou=some,o=org
cn=somethingelse, ou=same, o=org
cn=same, ou=some,ou=something, o=org
Could some one help to do this with regular expression. I need to lot of export, cleans and import the data to ldap.
Thanks
If I understand your goal correctly, thy these three Regex Replace Alls. The Replace with in the first two is nothing, blank, zip, nada.
Code: Select all
Find what: [[:blank:]]+$
Replace with:
Find what: \n
Replace with:
Find what: (cn[=])
Replace with: \n\1
(2[Bb]|[^2].|.[^Bb])
That is the question.
That is the question.
OK, let's try this. The first Replace with is nothing, to eliminate trailing blanks.
Code: Select all
Find what: [[:blank:]]+$
Replace with:
Find what: \n([^c][^n][^=])
Replace with: \1
(2[Bb]|[^2].|.[^Bb])
That is the question.
That is the question.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
To show your examples with their original layout, including leading white space, enclose them in [/color][/b] tags (without the space I've added to stop the tags being interpreted here). I had to examine the source of the page to understand your requirement.
1. To remove each line that starts with a space:
Code: Select all
[/color][/b] ... [b][color=blue]
1. To remove each line that starts with a space:
2. To join each line that starts with space to the line that precedes it:Find what: ^_.*\n [Replace the underscore with a space]
Replace with: [nothing]
[X] Regular expression
Replace All
[Edit: Error in second regex corrected.]Find what: \n_ [Replace the underscore with a space]
Replace with: [nothing]
[X] Regular expression
Replace All
Last edited by ben_josephs on Wed Dec 28, 2011 7:06 pm, edited 1 time in total.
Thanks Ben
First one worked to remove the lines that start with a space but second one did not work to join the lines
that starts with space to the preceding line.
I get the can not find regular expression error. I made sure Regular Expression checkbox selected.
First one worked to remove the lines that start with a space but second one did not work to join the lines
that starts with space to the preceding line.
I get the can not find regular expression error. I made sure Regular Expression checkbox selected.
where _ is a space in my file. I need following ouput.dn: cn=user,ou=test,ou=test,dc=xxxx,
_dc=yyyy,dc=org
memberof: cn=groupone,ou=test,ou=testa,dc=xx
_xx,dc=yyyy,dc=org
memberof: cn=grouptwo,ou=test,ou=testa,dc=xxxx,
_dc=yyyy,dc=org
memberof: cn=groupthree,ou=test,ou=testa,dc=xxxx,d
_c=yyyyy,dc=org
Thanks again.dn: cn=user,ou=test,ou=test,dc=xxxx,dc=yyyy,dc=org
memberof: cn=groupone,ou=test,ou=testa,dc=xxxx,dc=yyyy,dc=org
memberof: cn=grouptwo,ou=test,ou=testa,dc=xxxx,dc=yyyy,dc=org
memberof: cn=groupthree,ou=test,ou=testa,dc=xxxx,dc=yyyyy,dc=org
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
I just tried again but no luck. I did not use it with first one as I had to use those on two different files.
As the first one worked, I been working on the second where I need to join the lines with preceding lines.
I'm using following..
Thanks again.
As the first one worked, I been working on the second where I need to join the lines with preceding lines.
I'm using following..
Code: Select all
Find what: ^\n- (space instead of -)
Replace with: n/a
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm