![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing last character from each line of file | cjhancock | Shell Programming and Scripting | 17 | 08-29-2008 01:05 AM |
| removing particular lines ending with a .cnt extension in a text file | ramky79 | SUN Solaris | 2 | 03-03-2008 01:17 AM |
| Removing a particular line from a text file | sendhilmani123 | Shell Programming and Scripting | 5 | 05-31-2006 05:32 AM |
| Removing lines in a text file. | WABonnett | Shell Programming and Scripting | 4 | 11-25-2003 07:27 AM |
| removing commas from text file | hcclnoodles | UNIX for Dummies Questions & Answers | 6 | 03-26-2003 12:43 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi All,
I would like to know how to remove text from a line in a file. eg [na *oparea* check 0 nul 6376000 nlr 6374000 eul 318000 elr 320000] to [na *oparea* check 0] The 4 sets of numbers are not static ie they change on each line in each different file so if anyone can help that would be great. Jeremy |
| Forum Sponsor | ||
|
|
|
|||
|
Hopefully the entire line does not have to matched and a shorter regexp will suffice:
perl -pi -e 's/^(\Q[na *oparea* check \E\d+).*/$1]/' file The only advantage is a more readable code. The disadvantage is false matches are possible if the entire line needs to be matched |
|
|||
|
removing text
perl -pi -e 's/^(\Q[na *oparea* check \E\d+).*/$1]/' file
perl -pi -e 's/(\[na\s+\*oparea\*\s+check\s+\d+)\s+nul\s+\d+\s+nlr\s+\d+\s+eul\s+\d+\s+elr\s+\d+\]/\1]/' newfile I have tried both of these lines, but they just make the output file empty |
|
|||
|
don't have to use regular expression. Unless i read your requirement wrong,
Code:
open(F, "<file") or die "cannot open file:$!\n";
while ( <F> ) {
if ( /nul/ ) {
@a = split(/nul/);
print $a[0] . "]\n";
}
}
close(F);
Code:
# ./test.pl [na *oparea* check 0 ] |