473,581 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete a line from file

123 New Member
hey all,
I want to remove the below line from the resulting text...
Expand|Select|Wrap|Line Numbers
  1. (.*)$/',$lines,$matches))10.(.*)$/',$lines,$matches))(.*)$/',$lines,$matches))
  2.  
i used
Expand|Select|Wrap|Line Numbers
  1. perl -pi -e 's/\(.*\)\$/',\$lines,\$matches\)\)10.\(.*\)\$/',\$lines,\$matches\)\)\(.*\)\$/',\$lines,\$matches\)\) / /gi' result.txt > result1.txt
  2.  
But dint work..
Please help me..
Jul 15 '08 #1
21 4412
KevinADC
4,059 Recognized Expert Specialist
Try this instead:

Expand|Select|Wrap|Line Numbers
  1. perl -pi -e 's#\Q(.*)\$/',\$lines,\$matches))10.(.*)\$/',\$lines,\$matches))(.*)\$/',\$lines,\$matches))# #gi' result.txt > result1.txt
  2.  
\Q will escape all the meta characters in the pattern except $ and @. So I escaped all the $ manually.
Jul 15 '08 #2
ajd335
123 New Member
Try this instead:

Expand|Select|Wrap|Line Numbers
  1. perl -pi -e 's#\Q(.*)\$/',\$lines,\$matches))10.(.*)\$/',\$lines,\$matches))(.*)\$/',\$lines,\$matches))# #gi' result.txt > result1.txt
  2.  
\Q will escape all the meta characters in the pattern except $ and @. So I escaped all the $ manually.
Hi Kevin,
when I tried above , It gives me
" Unmatched '. "
Why its giving that?
Jul 15 '08 #3
KevinADC
4,059 Recognized Expert Specialist
oops, try like this instead:

Expand|Select|Wrap|Line Numbers
  1. perl -pi -e 's#\Q(.*)\$/\',\$lines,\$matches))10.(.*)\$/\',\$lines,\$matches))(.*)\$/\',\$lines,\$matches))# #gi' result.txt > result1.txt
the single quotes inside the pattern have to be escaped.
Jul 16 '08 #4
alampally
5 New Member
Expand|Select|Wrap|Line Numbers
  1. ######################################
  2. # subroutine delete file
  3. ######################################
  4.  
  5. sub Delete
  6. {
  7.  
  8. $out="cgi-bin/order/$ENV{'REMOTE_ADDR'}.txt";
  9.  
  10. open OUT, "$out" or die "Cannot open $out for write :$!";
  11.  
  12. read(OUT,$oldstuff,10000);
  13.  
  14. close OUT;
  15.  
  16. @changes=split(/n/,$oldstuff);
  17.  
  18. open OUT, ">$out" or die "Cannot open $out for write :$!";
  19.  
  20. undef $changes[$fields{linenumber}]; ### this leaves a blank line which messes up my output ###
  21.  
  22.  
  23. for $x (0 .. $#changes) 
  24.  
  25. {
  26. print OUT "$changes[$x]n";
  27. }
  28.  
  29. close OUT;
  30.  
  31. }
  32.  
  33. ######################################
  34. # subroutine adjust file
  35. ######################################
  36.  
  37. sub Adjust
  38. {
  39.  
  40. $out="cgi-bin/order/$ENV{'REMOTE_ADDR'}.txt";
  41.  
  42. open OUT, "$out" or die "Cannot open $out for write :$!";
  43.  
  44. read(OUT,$oldstuff,10000);
  45.  
  46. close OUT;
  47.  
  48. @changes=split(/n/,$oldstuff);
  49.  
  50. open OUT, ">$out" or die "Cannot open $out for write :$!";
  51.  
  52. $changes[$fields{linenumber}]=$adjust;
  53.  
  54. for $x (0 .. $#changes) 
  55.  
  56. {
  57. print OUT "$changes[$x]n";
  58. }
  59.  
  60. close OUT;
  61.  
  62. }
  63.  
Write me for any help in C,C++,Perl,PHP and Unix related stuff. I will answer you with in the time with free of cost.

Rammohan Alampally,
HP Technologies
Bangalore
EMAIL AND URL REMOVED! AGAINST SITE POSTING POLICY
Jul 16 '08 #5
numberwhun
3,509 Recognized Expert Moderator Specialist
alampally,

Before you post to any other forums here on bytes.com, please read our Posting Guidelines. You seem to consistently break them and need to please read and understand them.

Regards,

Jeff
Jul 16 '08 #6
ajd335
123 New Member
oops, try like this instead:

Expand|Select|Wrap|Line Numbers
  1. perl -pi -e 's#\Q(.*)\$/\',\$lines,\$matches))10.(.*)\$/\',\$lines,\$matches))(.*)\$/\',\$lines,\$matches))# #gi' result.txt > result1.txt
the single quotes inside the pattern have to be escaped.
Hi Kevin,
Thanks for the help..
Kevin again i get the same error ,
( Unmatched ' . )
my line is
Expand|Select|Wrap|Line Numbers
  1. (.*)$/',$lines,$matches)        10.(.*)$/',$lines,$matches)     (.*)$/',$lines,$matches)
  2.  
There is a Tab between .
What can be done ?
Thanks...
Jul 16 '08 #7
numberwhun
3,509 Recognized Expert Moderator Specialist
As mentioned earlier to another OP in this post, code tags are required. You used them in your first post, please use them to surround any code you provide.

Thank you!

Regards,

Moderator
Jul 16 '08 #8
ajd335
123 New Member
As mentioned earlier to another OP in this post, code tags are required. You used them in your first post, please use them to surround any code you provide.

Thank you!

Regards,

Moderator
Oh Sorry,
I'll take care of that..
Jul 16 '08 #9
KevinADC
4,059 Recognized Expert Specialist
Expand|Select|Wrap|Line Numbers
  1. ######################################
  2. # subroutine delete file
  3. ######################################
  4.  
  5. sub Delete
  6. {
  7.  
  8. $out="cgi-bin/order/$ENV{'REMOTE_ADDR'}.txt";
  9.  
  10. open OUT, "$out" or die "Cannot open $out for write :$!";
  11.  
  12. read(OUT,$oldstuff,10000);
  13.  
  14. close OUT;
  15.  
  16. @changes=split(/n/,$oldstuff);
  17.  
  18. open OUT, ">$out" or die "Cannot open $out for write :$!";
  19.  
  20. undef $changes[$fields{linenumber}]; ### this leaves a blank line which messes up my output ###
  21.  
  22.  
  23. for $x (0 .. $#changes) 
  24.  
  25. {
  26. print OUT "$changes[$x]n";
  27. }
  28.  
  29. close OUT;
  30.  
  31. }
  32.  
  33. ######################################
  34. # subroutine adjust file
  35. ######################################
  36.  
  37. sub Adjust
  38. {
  39.  
  40. $out="cgi-bin/order/$ENV{'REMOTE_ADDR'}.txt";
  41.  
  42. open OUT, "$out" or die "Cannot open $out for write :$!";
  43.  
  44. read(OUT,$oldstuff,10000);
  45.  
  46. close OUT;
  47.  
  48. @changes=split(/n/,$oldstuff);
  49.  
  50. open OUT, ">$out" or die "Cannot open $out for write :$!";
  51.  
  52. $changes[$fields{linenumber}]=$adjust;
  53.  
  54. for $x (0 .. $#changes) 
  55.  
  56. {
  57. print OUT "$changes[$x]n";
  58. }
  59.  
  60. close OUT;
  61.  
  62. }
  63.  
Write me for any help in C,C++,Perl,PHP and Unix related stuff. I will answer you with in the time with free of cost.

Rammohan Alampally,
HP Technologies
Bangalore
EMAIL AND URL REMOVED! AGAINST SITE POSTING POLICY

I was very pleased to see a new person posting in the perl forum but it has become evident that your real purpose is to post your advertising. You are offering suggestions that sometimes do not even really apply to the question, like your above code. Your advertising could be tolerated, at least by me personally, if your suggestions were better thought out and relevant to the question and not posted in old threads like you did previously (not this thread). I hope you continue to post but I also hope you offer better replies and stop violating the forum policy of posting signatures with email addresses and advertising.

Regards,
Kevin
Jul 16 '08 #10

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

Similar topics

5
5229
by: | last post by:
Hi all, I've been using C++ for quite a while now and I've come to the point where I need to overload new and delete inorder to track memory and probably some profiling stuff too. I know that discussions of new and delete is a pretty damn involved process but I'll try to stick to the main information I'm looking for currently. I've searched...
5
18566
by: ad | last post by:
I want to delete some text which begin with <!DOCTYPE and end with > in a file. How can I do it?
6
2574
by: I am Sam | last post by:
I keep getting this error and I don't know why: The path is too long after being fully qualified. Make sure path is less than 260 characters. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code....
6
2358
by: santa19992000 | last post by:
I have a file called xyz.txt, if the first word matches, I have to delete the whole line, how can I do that. sample is below file xyz.txt ======= SP 0/23/2345/345 CL 00/34/3456/54 In the above file, if the first word "SP" matches, then I have to delete the whole line in that file, How to delete. Thanks.
3
4640
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >> 0x804d008 _Delete unknown block >> registered : 0x804d138 >> 0x804d008 _Delete unknown block >> 0x804d098 _Delete ok
9
10255
by: groleo | last post by:
Hi list. Simple question: is it possible to override the global new/delete operators, without using malloc/free? I mean something in the ideea of the code below, which doesnt work cause of the recursivenes. What I'm trying to say is how to override new/delete using the original global
9
7031
by: Juergen Huber | last post by:
hello, i am a dummy user in python and new in this programming language and so there will be questions, that´s for you no problem! i never have before programmed in any language! sorry for this! i hope you will help me, that i also could the basics in this language! and later many more, so i hope ! :) the first question for me in this...
4
5549
by: jeepers | last post by:
Hi all, my problem is delete a line in a text file. the file contain -n line with user, userCode. i want to replace the line with user is egual at user, and/or insert new line but delete the line like user. i'm sorry for my english :D if user exist delete a line of the user and insert new line. if not exist insert new line. possibility...
10
12206
by: Joah Senegal | last post by:
Hello all, I want something that should be realy really simple.... but I dont get it.. searched google and stuf, but found nothing useful. I;m opening a txt-file with a fstream. Now I want to make a function that looks like Removeline(int Linenumber); But I can;t get it working.. anybody has anything helpfull? if anybody can help me...
2
19735
by: Francesco Pietra | last post by:
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line: print line f.close()
0
7792
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...
0
8149
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. ...
0
8304
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...
0
6553
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5674
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...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2301
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 we have to send another system
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1138
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...

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.