473,651 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to exclude lines from a txt file that start with a #

154 New Member
How to exclude lines from a txt file that start with a #

Hi basically my script works fine.

I wanted to add some comments in my config file but it is reading in the comment lines to.

So basically i want to not read in the config lines in the script.

This is the piece of the script that is reading in the lines in the array.
Now it works fine without the if statement. So reason it is not working.

Expand|Select|Wrap|Line Numbers
  1. open(HAN, "sort_config.txt") || die " Unable to run date command $!";
  2.  
  3.   while (<HAN>) {
  4.           $configline = <HAN>;
  5.         # This if statement is to remove lines from the array that start with #
  6.          chomp($configline);
  7.          if ("$configline" =~ /^\#/) {
  8.             print "not in array $configline \n";
  9.                                      }
  10. else {
  11. push @array1, [ split ];  
  12. print "going in array $configline \n";
  13.                   }
  14. close HAN;
  15.                  }
-------------------------------------------------------------
Config files lines are:
# CONFIG FILE ####### Delimiter is 1 space ***** DO NOT REMOVE LINE ****
# SOURCE PATH DESTINATION PATH LOG PATH AND FILE ***** DO NOT REMOVE LINE ****
# EXAMPLE: /home/source /home/archive /home/newlog.txt ***** DO NOT REMOVE LINE ****
/home/source3 /home/archive /home/newlog3.txt
/home/source4 /home/archive2 /home/newlog4.txt

So basically i want the array to have only lines with no #
Nov 29 '07 #1
2 1946
eWish
971 Recognized Expert Contributor
Try replacing the if statement in the while loop to the following.

Expand|Select|Wrap|Line Numbers
  1. #untested
  2. next if $configline =~ (/^#/);
--Kevin
Nov 29 '07 #2
pramodkh
23 New Member
Try replacing the if statement in the while loop to the following.

Expand|Select|Wrap|Line Numbers
  1. #untested
  2. next if $configline =~ (/^#/);
--Kevin
Yes...deffinate ly Kevin's reply should solve your problem. But i suggest you to use Config::IniFile s module to work with config files. You can get more details about this module in CPAN.

Regards
Pramod
Nov 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

26
11757
by: Shannon Jacobs | last post by:
Sorry to ask what is surely a trivial question. Also sorry that I don't have my current code version on hand, but... Anyway, must be some problem with trying to do the negative. It seems like I get into these ruts each time I try to deal with regular expressions. All I'm trying to do is delete the lines which don't contain a particular string. Actually a filter to edit a log file. I can find and replace a thing with null, but can't...
6
2112
by: xxnonexnonexx | last post by:
I am looking to do some email validation and many of the scripts I've located online are great basic email validators. They check to see that the email address is something along the lines of somethin@a_valid_host.at_a_valid_tld Thats great, looking for that, BUT I then want to EXCLUDE certain domains, ie: webmail hosts, or what ever hosts I add to a list.
1
5473
by: Rajesh Abraham | last post by:
I would like to Exclude MyApp.Exe.Config from my Setup Package as I don't want it to get overwritten during upgrade installation of my application. If I remove app.config while building the setup, it removes existing app.config on the target machines and if included, it overwrites the existing ones. I tried editing the msi package and removing the app.config file from the table but it did not work. Any
1
1533
by: John Dalberg | last post by:
In VS 2003, I was able to exclude full folders from a project but I can't do the same in VS 2005. I can exclude files but not folders. I prefer to exclude at the folder level because the folder icon has visual indicator. John Dalberg
15
9917
by: batman | last post by:
i have a text file that is like: date = OCT0606 asdf sdaf asdfasdgsdgh asdfsdfasdg START-OF-DATA asdfasdfg asdfgdfgsfg
1
1581
by: AntiChrist | last post by:
In VS 2005 if you exclude files from a project, it actually renames the file to filename.exclude. In previous versions, it just left the file alone but excluded it. If you have a very large ASP.net web site you may have thousands of images. In our case we have millions because the nature of the site is that users upload their photo albums to share with other users. I NEVER want the IDE to enumerate these files for any reason, including...
0
1431
by: tom | last post by:
I would like to use Epydoc (3.0beta1) to document my wxPython (2.6.10) application. The problem is that I can't seem to instruct Epydoc to not also generate partial documentation of wxPython, which makes too much verbiage for a user to wade through in order see the documentation of my program. For example, if my module consists of only the three lines import wx class BasicPanel(wx.Panel):
1
1226
by: bmdlfc | last post by:
Morning all, long time reader, first time poster. I need to manipulate an existing CSV file and create another one from it but excluding some fields. For example, the fields I have in the 'master' file are: searchtime, viewid, depair, destair, resort, depdate, nights, hotel, rating, roominfo, boardbasis, price, adults, link, picture I need to read through that file and only include depair, destair, depdate, resort, price, link,...
2
4092
by: rka77 | last post by:
Hi, I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file - Set : 1 Date: 10212009 12 34 56 25 67 90 End Set ******** Set: 2 Date: 10222009
0
8352
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.