remove specific lines from flat file using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove specific lines from flat file using perl
# 8  
Old 02-12-2008
a tab can be represented by a \t, or you can maybe use the syntax like

\s+ (one or multiple whitespace characters, spaces and tabs)..

when you google for "perl find metasymbols" you will find some more explaining about these options.
# 9  
Old 02-12-2008
Thanks.. i will do a search on it..
# 10  
Old 02-12-2008
Don't know what you exactly want, but sometimes is more easy to search for what you want than to exclude the things you don't want, remember there are many way's how you can solve the issues with perl.
# 11  
Old 02-12-2008
im sorry about the last post.. it was some weird character i couldnt copy it properly... i have a question...
foreach my $file (@array) {
open(FILE,"<","$file");
while (my $line = <FILE>)
{
if ($line =~ /^*/){
print $line;
}
}
close(FILE);
}

im looking to print all the ripped contents from each file to other different files.. example... if im going through file1, file2, file3...filen .. im looking to write to file1_1, file2_1, file3_1, ... filen_1 .. something like that instead of print $line;
# 12  
Old 02-12-2008
bare bones script:

Code:
open(my $in, 'infile.txt');
LOOP: while(<$in>){
   if (/COL1 COL2/) {
      print $_;
      while (<$in>) {
         print $_;
         last LOOP if (/100 z/);
      }
   }
}

see if you can figure out how to implement according to the rest of your requirements. If not, post back.
# 13  
Old 02-12-2008
Quote:
Originally Posted by meghana
(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);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove lines in file if specific field matches

I am trying to remove lines in the target.txt file if $5 before the - in that file matches sorted_list. I have tried grep and awk. Thank you :). grep grep -v -F -f targets.bed sort_list grep -vFf sort_list targets awk awk -F, ' > FILENAME == ARGV {to_remove=1; next} > ! ($5 in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. UNIX for Advanced & Expert Users

Remove duplicates in flat file

Hi all, I have a issues while loading a flat file to the DB. It is taking much time. When analyzed i found out that there are duplicates entry in the flat file. There are 2 type of Duplicate entry. 1) is entire row is duplicate. ( i can use sort | uniq) to remove the duplicated entry. 2) the... (4 Replies)
Discussion started by: samjoshuab
4 Replies

3. Shell Programming and Scripting

Remove somewhat Duplicate records from a flat file

I have a flat file that contains records similar to the following two lines; 1984/11/08 7 700000 123456789 2 1984/11/08 1941/05/19 7 700000 123456789 2 The 123456789 2 represents an account number, this is how I identify the duplicate record. The ### signs represent... (4 Replies)
Discussion started by: jolney
4 Replies

4. UNIX for Dummies Questions & Answers

Search flat file in specific byte

I am on AIX Unix. I want to read a flat file for a string in a certain byte. I want to find the value: 943034 in column 56; and write out just those records to another file. Also, could I get the line/record number of where it was found in the input file? Thank you, sboxtops (1 Reply)
Discussion started by: sboxtops
1 Replies

5. UNIX for Dummies Questions & Answers

how to remove the first line from a flat file ?

Hi, I want to remove the first line from a flat file using unix command as simple as possible. Can anybody give me a hand ? Thanks in advance. xli (21 Replies)
Discussion started by: xli
21 Replies

6. Shell Programming and Scripting

how to remove specific lines from a file (reprise)

Hello, I've to change the shell in /etc/passwd for some users . I've the list of users but I'm not able to modify the file with scripting . I'm working on a Sol10 . Can anyone help me ? tnks (7 Replies)
Discussion started by: gogol_bordello
7 Replies

7. Shell Programming and Scripting

How to remove the specific lines from file using perl

Can anyone tell me what could be the solution to following : I have one .txt file which contains some "seed" information. This seed may appear multiple time in the file so what I want do is if this seed appears again in the file then that line should be removed. Please provide the script code... (4 Replies)
Discussion started by: dipakg
4 Replies

8. Shell Programming and Scripting

How to remove the lines from file using perl

Can anyone tell me what could be the solution to following : I have one .txt file which contains some seed information. This seed may appear multiple time in the file so what I want do is if this seed appears again in the file then that line should be removed. here is the contents of .txt... (5 Replies)
Discussion started by: dipakg
5 Replies

9. Shell Programming and Scripting

how to remove specific lines from a file

When restoring a file in my uninstall program I need to remove the lines I added to a file during the install. In between the file can be modified by the users. Assume file1 is as follow: xxx str2 xxxx ..... ...The Following lines containing str* have to be removed... xxx str1 xxxx xxx ... (17 Replies)
Discussion started by: bluemoon1
17 Replies

10. Shell Programming and Scripting

remove specific lines from a file

Hi there I have a file with a variable amount of rows but the 45th, 46th and 47th charachter of each line is the status field which is a three digit code ie 001, 002, 003 etc. My question is this..I need to strip all the records/lines with 002's out of the file completely and put them into... (14 Replies)
Discussion started by: hcclnoodles
14 Replies
Login or Register to Ask a Question