perl one-liner?

H

haiwu.us

I have one ldif file, which is a dump file from Oracle OID. Many lines
got cut into 2 lines due to 80 columns limit, not sure why. So there
are many similar lines as follows in the file (there will always be an
empty space char in the beginning of the 2nd line):

cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oracleco
ntext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclec
ontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Ent
erprise Manager.

I want to change the above to below:
cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Enterprise Manager.

Is it possible for perl one-liner?
 
U

usenet

Is it possible for perl one-liner?

One can (possibly/probably) write ten thousand 'lines' of Perl in one
line (with 9_999 semi-colons). Just out of curiosity, why do you care
what the line count is?
 
A

Anno Siegel

I have one ldif file, which is a dump file from Oracle OID. Many lines
got cut into 2 lines due to 80 columns limit, not sure why. So there
are many similar lines as follows in the file (there will always be an
empty space char in the beginning of the 2nd line):

cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oracleco
ntext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclec
ontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Ent
erprise Manager.

I want to change the above to below:
cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Enterprise Manager.

Is it possible for perl one-liner?

I don't know about a one-liner. Here is the standard way of dealing
with continuation lines:

my $buf;
while ( <DATA> ) {
chomp;
if ( s/^ // ) {
$buf .= $_;
} else {
print "$buf\n" if $buf;
$buf = $_;
}
}
print "$buf\n" if $buf;

Anno
 
J

John W. Krahn

I have one ldif file, which is a dump file from Oracle OID. Many lines
got cut into 2 lines due to 80 columns limit, not sure why. So there
are many similar lines as follows in the file (there will always be an
empty space char in the beginning of the 2nd line):

cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oracleco
ntext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclec
ontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Ent
erprise Manager.

I want to change the above to below:
cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Enterprise Manager.

Is it possible for perl one-liner?

perl -lpe'BEGIN{$/="\n ";$\=""}' yourfile



John
 
X

Xicheng

I have one ldif file, which is a dump file from Oracle OID. Many lines
got cut into 2 lines due to 80 columns limit, not sure why. So there
are many similar lines as follows in the file (there will always be an
empty space char in the beginning of the 2nd line):

cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oracleco
ntext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclec
ontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Ent
erprise Manager.

I want to change the above to below:
cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Enterprise Manager.

Is it possible for perl one-liner?

perl -ln0e '$m=$1,($n=$2)=~s/\s*\n\s*//g and print "$m: $n"
while/^([^:]*):\s*([^:]*)(?=^[^:]*:|$)/mg' file.txt

this may roughly do it, except that in the fourth line, "user of" is
changed to "userof".. I dont know why you left spaces between "Ent" and
"erprise", if I chomped these whitespaces, I also chomped the
whitespaces between normal texts like "user" and "of". so what's your
rule to distinguish between these two??..

Xicheng
 
H

haiwu.us

This can be done using one line sed command. I am thinking perl would
probably do a better job than sed in this case.
 
X

Xicheng

This can be done using one line sed command. I am thinking perl would
probably do a better job than sed in this case.

it depends on your data format? I am guessing the data you posted in
the group are not as your original format or I didn't understand your
requirements correctly. basically, perl can do most of the oneliners as
sed does...
Best,
Xicheng
 
H

haiwu.us

I mean this one: perl -lpe'BEGIN{$/="\n ";$\=""}' yourfile

I am using Google groups. If you look at using its tree view, you will
see.
 
H

haiwu.us

This is a file created in Linux using Oracle OID ldifwrite. I don't
know why it split output lines longer than 80 chars into 2 lines, with
the 2nd line having one empty space char in its beginning.

That line should look like this: (I am omitting the beginning since I
am afraid this HTML form will also wrap the line)
UDDI Registry Administrator. It maps to the ias_admin user of Ent
erprise Manager.

It should be changed to:
UDDI Registry Administrator. It maps to the ias_admin user of
Enterprise Manager.
 
T

Tad McClellan

I have one ldif file, which is a dump file from Oracle OID. Many lines
got cut into 2 lines due to 80 columns limit, not sure why. So there
are many similar lines as follows in the file (there will always be an
empty space char in the beginning of the 2nd line):

cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oracleco
ntext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclec
ontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Ent
erprise Manager.

I want to change the above to below:
cn: ias_admin
creatorsname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
modifiersname:
orclapplicationcommonname=uddi,cn=portal,cn=products,cn=oraclecontext
description: UDDI Registry Administrator. It maps to the ias_admin user
of Enterprise Manager.

Is it possible for perl one-liner?


Playing fast and loose with newlines:

perl -ne 'print("\n"), chomp, print, next unless s/^ //; chomp, print' file


Getting the newlines right makes it rather unwieldly for a one-liner:

perl -ne 'print($.==1 ? "" : "\n"), chomp, print, next unless s/^ //; chomp, print; END{print"\n"}' file


I think I'd write a dozen lines of clear code instead.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g47g2000cwa.googlegroups.com:
I mean this one: perl -lpe'BEGIN{$/="\n ";$\=""}' yourfile

I am using Google groups. If you look at using its tree view, you will
see.

Google Groups is just another interface to the UseNet (and not a
particularly good one).

On the UseNet, it is customary to quote the message one is replying to,
along with an attribution to the author.

See http://groups.google.com/support/bin/answer.py?answer=14213&topic=250
as well as the posting guidelines for this group to learn how you can
benefit from participating in this group.

Sinan
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g43g2000cwa.googlegroups.com:

[ Please quote some context when you reply ]
This is a file created in Linux using Oracle OID ldifwrite. I don't
know why it split output lines longer than 80 chars into 2 lines, with
the 2nd line having one empty space char in its beginning.

That line should look like this: (I am omitting the beginning since I
am afraid this HTML form will also wrap the line)
UDDI Registry Administrator. It maps to the ias_admin user of Ent
erprise Manager.

It should be changed to:
UDDI Registry Administrator. It maps to the ias_admin user of
Enterprise Manager.

Go ahead and change it, then.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,511
Latest member
svareza

Latest Threads

Top