The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-12-2008
meghana meghana is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 56
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
  #2 (permalink)  
Old 02-12-2008
meghana meghana is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 56
can anyone help on this!!!
  #3 (permalink)  
Old 02-12-2008
rvegmond rvegmond is offline
Registered User
  
 

Join Date: Feb 2008
Location: The Netherlands
Posts: 39
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..
  #4 (permalink)  
Old 02-12-2008
meghana meghana is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 56
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??
  #5 (permalink)  
Old 02-12-2008
rvegmond rvegmond is offline
Registered User
  
 

Join Date: Feb 2008
Location: The Netherlands
Posts: 39
the * stands for "match 0 or more times", think you need to escape the *:

if ($line =~ /^\*/){
  #6 (permalink)  
Old 02-12-2008
meghana meghana is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 56
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
  #7 (permalink)  
Old 02-12-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by meghana View Post
(Looking for perl code)
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);
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0