473,503 Members | 5,382 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 1922
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...deffinately Kevin's reply should solve your problem. But i suggest you to use Config::IniFiles 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
11725
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...
6
2101
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...
1
5441
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...
1
1524
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...
15
9878
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
1571
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...
0
1419
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,...
1
1218
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...
2
4081
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:...
0
7067
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...
0
7316
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...
1
6975
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...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
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...

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.