![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to remove the first line from a flat file ? | xli | UNIX for Dummies Questions & Answers | 21 | 12-16-2008 01:37 AM |
| How to remove the specific lines from file using perl | dipakg | Shell Programming and Scripting | 4 | 06-11-2008 02:45 AM |
| How to remove the lines from file using perl | dipakg | Shell Programming and Scripting | 5 | 06-03-2008 07:49 AM |
| how to remove specific lines from a file | bluemoon1 | Shell Programming and Scripting | 17 | 10-07-2007 10:40 PM |
| remove specific lines from a file | hcclnoodles | Shell Programming and Scripting | 14 | 09-07-2006 12:31 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
remove specific lines from flat file using perl
Hi,
Here is wat im looking for.. i have a flat file which looks like this.. 00 * * * * .. .. * * text text text COL1 COL2 ----- ----- 1 a 2 b 3 c .... .... 100 z text text text * * ... ... * I just want to retrieve.. COL1 COL2 ----- ----- 1 a 2 b 3 c .... .... 100 z (Looking for perl code) Thanks, Megha |
|
||||
|
you can try to parse the contents of the file and compare the lines you are reading, maybey something like this (will require some polishing):
open(FH, $filename); while (<FH>) { print $_ if ($_ =~ / /); } in other words, will print the line if it contains a space, but it may be not what you are requiring, for that some more info may come in handy.. |
|
||||
|
open(FILE,"<","Test.TXT");
while (my $line = <FILE>) { if ($line =~ /^*/){ print $line; } } close(FILE); Here is what i was trying to do to pick up the lines that start with '*' .. but its not picking up.. can you help me on this?? |
|
||||
|
Thats works... i have a tab in the beginning of a line.. can you tell me how to represent a "tab" in a search string... i used ($line =~ m/^\*/) && ($line =~ m/^\ /) .. respectively for a '*' character and ' ' space.. need to work to get a "tab" too...
Thanks |
|
||||
|
try to do some code next time.
one way. Code:
#!/usr/bin/perl
open(F, "<file") or die "cannot open file:$!\n";
while ( <F> ) {
if ( /COL1 COL2/ .. /^$/ ) {
print;
}
}
close(F);
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|