20070926 more on editing files with perl - plembo/onemoretech GitHub Wiki

title: More on editing files with Perl link: https://onemoretech.wordpress.com/2007/09/26/more-on-editing-files-with-perl/ author: lembobro description: post_id: 631 created: 2007/09/26 18:28:26 created_gmt: 2007/09/26 18:28:26 comment_status: open post_name: more-on-editing-files-with-perl status: publish post_type: post

More on editing files with Perl

Had to do this today on an LDIF file.

Say you have a data file called “users.ldif” containing multiple lines that begin with the same series of characters, and you want to remove all those lines without leaving gaps. For example, take this LDIF file snippet:

`

dn: cn=testuser,cn=Users,dc=example,dc=com
cn: testuser
sn: Test
givenname: User
createtimestamp: 20070912172959z
...

`

If you’d like to remove that last line, wherever it appears in the file (and under certain circumstances it will appear EVERYWHERE), you could do that with the following Perl one-liner:

`

perl -pi -e 's/^createtimestamp.+n$//' users.ldif

`

Voila! You’ve edited a file with Perl!

Copyright 2004-2019 Phil Lembo