Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
was wondering if you could help me with a script to remove ALL the lines in a file that contain the word "BOUNDARY". I have the script like this so far, but It will only remove the first occurance of BOUNDRY, not all of them like I want.
#!/bin/bash
line=$(grep -n "BOUNDARY" foo.c | cut -d: -f1 | sed '1q' )
sed ${line}d foo.c > foo_new.c
thanks for your help.

I did a similar script like this to upload files from forms. It relied heavily on regular expressions, which is what I would use here. If you want the whole script, I'll e-mail it to you. But for now, here is a line of code that removes all lines that contain the word BOUNDARY (case-sensitive) from a scalar:
$myfile =~ s/^.*BOUNDARY.*$//g;
s - search and replace
^ - match beginning of a line
.* - match any (non line ending) character 0 or more times
BOUNDARY - match BOUNDARY
.* - match any (non line ending) character 0 or more times
$ - match end of line
// - replace the matches with nothing
g - do it globally (everywhere)Judging by the context, it may be helpful for you in whatever project you're doing to split the file into separate scalars using a line with the word BOUNDARY as a delimiter. If so, then you could use
@mygoodstuff =~ split/^.*BOUNDARY.*$/$myfile/;
The regular expression may need a little adjustment, post back if it doesn't work. Or if it does, for that matter, for curiosity's sake.
As a disclaimer, remember that if you're dealing with large files, there is a relatively good chance that the word BOUNDARY may pop up where you don't want it to.
Good luck,
-SN

How about a perl (command line) script.
perl -pi -e "s/^.*BOUNDARY.*$//i" foo.c
If you want a back-up copy of the original file, modify it to:
perl -pi.old -e "s/^.*BOUNDARY.*$//i" foo.c
this will create a back-up file named foo.c.old
The i in the regex tells it to ignore case.

We have these files that are backed up on the serber into files. Sometimes it comments the first couples lines in the file causing an error. We need to completely remove the // and /*'s from the file.
I put into the pl file
$filename =~ s/^.*//.*$//g;
$filename =~ s/^.*/*.*$//g;Is this right am I going about this all wrong?
Please email me!! I need help ASAP!!

Thanks for your help guys the perl line and $myfile variable worked equally well. appreciate the help ;-)

![]() |
What's Up With All The VB
|
vb6 dirlistbox
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |