CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Need help with regex, spaces and newlines in file

 



Iconx
Novice

Jul 22, 2014, 8:07 AM

Post #1 of 2 (303 views)
Need help with regex, spaces and newlines in file Can't Post

So i have a file that goes something like this:

Code
file.txt 
------------------
this is line one
line two


line five
line six
----------------------

I'm not sure whats in the blank spaces there, could be space, could be cairrage return, dunno.
Is there a good way to detect and clear these?

I've tryed:

if ( $line =~ /^\s*$/ ) {
if($line =~ /^\s+\Z/)
I've even tried various sed commands and they return

sed: -e expression #1, char 14: unterminated address regex

How can I clear all blanks, cairrage returns tabs spaces whatever his holding these spaces in the file.

Iconx


BillKSmith
Veteran

Jul 22, 2014, 8:35 AM

Post #2 of 2 (301 views)
Re: [Iconx] Need help with regex, spaces and newlines in file [In reply to] Can't Post

Do you want to 'clear' lines which contain only whitespace?
Consider using the -i option to edit the file in place.

Note: The double quotes below are needed by windows. Most other operating systems require single quotes instead.


Code
>perl -ne"print unless /^\s*$/" file.txt


OUTPUT

Code
this is line one 
line two
line five
line six

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives