I need a script to remove lines from a file.

Hi,
    I work for an automotive group, and I need some help with a report file that we send out. The following is a sample.

S ORD/STK#  YEAR MAKE       MODEL      SERIES   BODY TYPE  D/S VIN
- --------- ---- ---------- ---------- -------- ---------- --- -----------------

W *0360089A 2004 ACURA      TL                  4DR SDN     13 19UUA65544A046034
R  003P1000 2003 ACURA      3.2TL               4DR SDN     42 19UUA56623A080487

It goes for about a page, and the the first two lines repeat themselves. I need the lines with the dashes removed, without disrupting the file otherwise.
I would appreciate the help, as I am just to busy to pull out my perl book, and hack this out. Thanks.
LVL 3
nalanbarAsked:
Who is Participating?
 
wlfsCommented:
Sorry, you are of course right. I forgot the quantifier. In order to keep blank lines in, it becomes a little bit more elaborate:
perl -ne 'print unless m/^\s*-+[\s-]*$/' <infile.txt >outfile.txt

I ran and tested it, so it should work fine now.
0
 
wlfsCommented:
unix:
perl -ne 'print unless m/^[\s-]$/' <infile.txt >outfile.txt

windows:
perl -ne "print unless m/^[\s-]$/" <infile.txt >outfile.txt
0
 
nalanbarAuthor Commented:
I ran the script, but the output still has the dashes...
0
 
Suhas .QA ManagerCommented:
Hi nalanbar,
#!/usr/bin/perl

open(IN,"D://test.txt");
open(OUT,">D://test_res.txt");
@arr = <IN>;
foreach $i (@arr) {
@arr1 = split(//,$i);
#print @arr1;
foreach $j (@arr1) {
    print "$j\n";
    if($j ne "-"){
        print OUT $j;}
    }
   
}

input (file.txt):
khihkhdashd
--------
hdifhdhf00---

output(file_res.txt):
khihkhdashd

hdifhdhf00

Cheers!
Suhas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.