469,330 Members | 1,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Delete a line from file

123 100+
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 4017
KevinADC
4,059 Expert 2GB
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 100+
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 Expert 2GB
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
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,503 Expert Mod 2GB
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 100+
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,503 Expert Mod 2GB
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 100+
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 Expert 2GB
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
KevinADC
4,059 Expert 2GB
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...
Is that literally the line in the file? Or are those perl variables ($lines,$matches). I'm getting confused.
Jul 16 '08 #11
numberwhun
3,503 Expert Mod 2GB
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
I fully agree, it is nice to see, it means we are (hopefully) doing something right. Considering that they joined this morning and did all their posting then, I hope that, as you said, they will continue, but modify their posting practices. As you saw, I posted a link to the policy in hopes that they would read and adhere to it.

Regards,

Jeff
Jul 16 '08 #12
ajd335
123 100+
Is that literally the line in the file? Or are those perl variables ($lines,$matches). I'm getting confused.
Hi Kevin ,
Yes , they are the lines only .Actually they are the result of preg_match(PHP) and have stored that in output file(i.e result.txt), which includes that line( It's bcz the result from preg_match).

Thanks,
Jul 16 '08 #13
KevinADC
4,059 Expert 2GB
Hi Kevin ,
Yes , they are the lines only .Actually they are the result of preg_match(PHP) and have stored that in output file(i.e result.txt), which includes that line( It's bcz the result from preg_match).

Thanks,
hmmm.... I'm stumped. To me it looks like it should work but evidently I am wrong or your code is different than what I have suggested you use. Try asking on www.perlmonks.com and see if one the members there can offer some suggestions. I know you could rewrite it as a script instead of a oneliner but it would be interesting to know why the oneliner is not working.
Jul 16 '08 #14
ajd335
123 100+
hmmm.... I'm stumped. To me it looks like it should work but evidently I am wrong or your code is different than what I have suggested you use. Try asking on www.perlmonks.com and see if one the members there can offer some suggestions. I know you could rewrite it as a script instead of a oneliner but it would be interesting to know why the oneliner is not working.
Thanks Kevin,
I have asked that q in perl monks...Lets c..
Thanks for the help...
Jul 16 '08 #15
ajd335
123 100+
Thanks Kevin,
I have asked that q in perl monks...Lets c..
Thanks for the help...
Hey Kevin,
They Asked me to use shell_escape , Just to know well , is it correct way to use shell_escape ?? as below.
Expand|Select|Wrap|Line Numbers
  1.  perl -pi -e shell_escape('s#\Q(.*)\$/\',\$lines,\$matches))10.(.*)\$/\',\$lines,\$matches))(.*)\$/\',\$lines,\$matches))# #gi')  result.txt > result1.txt
  2.  
  3.  
Thanks ,
Jul 16 '08 #16
KevinADC
4,059 Expert 2GB
There is no perl function shell_escape that I know of so maybe it is a function of a perl module, but I have not heard of it. You will have to ask the monks how to use that function.

I don't see the question posted on www.perlmonks.com
Jul 16 '08 #17
ajd335
123 100+
There is no perl function shell_escape that I know of so maybe it is a function of a perl module, but I have not heard of it. You will have to ask the monks how to use that function.

I don't see the question posted on www.perlmonks.com
Thanks Kevin,
Here's the link on perlmonks for my post..
http://perlmonks.org/index.pl?node_id=698176
Jul 16 '08 #18
numberwhun
3,503 Expert Mod 2GB
By shell-escape, they are meaning the back slash character.

If you keep reading the replies to your post on Perlmonks, Netwallah has a good trick that may work: ' " ' " '


Regards,

Jeff
Jul 17 '08 #19
ajd335
123 100+
By shell-escape, they are meaning the back slash character.

If you keep reading the replies to your post on Perlmonks, Netwallah has a good trick that may work: ' " ' " '


Regards,

Jeff
Hi NumberWhun,
Yes , you are right.they give good tricks to look for....I got the problem solved by changing some script in PHP only .But still learn so much from th help n replies..
Thanks.
Jul 17 '08 #20
KevinADC
4,059 Expert 2GB
You could avoid the whole issue by running a perl script instead of a oneliner that has to run in the shell and is subject to the whims of the shell. A little more code but much easier to write since there are no odd-ball shell considerations to take into account.
Jul 17 '08 #21
ajd335
123 100+
You could avoid the whole issue by running a perl script instead of a oneliner that has to run in the shell and is subject to the whims of the shell. A little more code but much easier to write since there are no odd-ball shell considerations to take into account.
Hi Kevin
May be yes , but still the desired script /code makes me do so...But , ya we can always avoid tedious code.
Thanks.
Jul 17 '08 #22

Post your reply

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

Similar topics

5 posts views Thread by | last post: by
5 posts views Thread by ad | last post: by
6 posts views Thread by I am Sam | last post: by
3 posts views Thread by silver360 | last post: by
9 posts views Thread by groleo | last post: by
9 posts views Thread by Juergen Huber | last post: by
10 posts views Thread by Joah Senegal | last post: by
2 posts views Thread by Francesco Pietra | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.