Skip to content
The Unix Tips
cat /vishal/brain > theunixtips.com
  • About
  • Contact Me
Perl

perl : Remove empty lines from an array

Posted on April 2, 2011 by Vishal Jain

Using grep the empty lines can be removed from an array in perl. Here is how.

### Remove any empty lines
@dataArray = grep(/S/, @dataArray);


S does the pattern matching that if everything on that line is a space.

 

  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • More
  • Click to share on Telegram (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Skype (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)
  • Click to email this to a friend (Opens in new window)
one-liner, perl
Vishal Jain
View all posts by Vishal Jain →

Post navigation

Older post
Howto rollover a file when size exceeds using unix find
Newer post
VirtualBox : Use Raw Disk to load Windows under Linux

You might also like

2 Comments

  1. Seth Williams says:
    February 12, 2016 at 8:22 pm

    You need the backslash before the ‘S’ like this: /S/

    1. kunwarvjain says:
      February 19, 2016 at 4:44 pm

      Thank you Seth, I have corrected.

Comments are closed.

Recent Posts

  • OTTO – Automate C/C++ CMake for Large Repositories
  • How to persist iptables settings on debian
  • How to Change Console Fonts In Ubuntu for 4K Screen
  • HP Spectre x360 convertible and Linux
  • HOWTO Develop Apache Module in C++

Top Posts

  • xming : Client 4 rejected from IP
  • perl : Extract filename from full path
  • How to persist iptables settings on debian
  • HP Spectre x360 convertible and Linux
  • bash : grep for pattern from certain location in the file
  • perl : Set different TimeZone for script
  • Hardware : Dell GX620 SFF HTPC Bootup problem due to burned up capactiors
  • Sendmail : Configure outgoing relay server
  • HOWTO Develop Apache Module in C++
  • How to Change Console Fonts In Ubuntu for 4K Screen

Recent Posts

  • OTTO – Automate C/C++ CMake for Large Repositories
  • How to persist iptables settings on debian
  • How to Change Console Fonts In Ubuntu for 4K Screen
  • HP Spectre x360 convertible and Linux
  • HOWTO Develop Apache Module in C++

Follow Me

  • LinkedIn
  • GitHub
© 2021 The Unix Tips
Powered by WordPress | Theme: Graphy by Themegraphy
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.