Link to home
Start Free TrialLog in
Avatar of nalanbar
nalanbarFlag for United States of America

asked on

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.
Avatar of wlfs
wlfs

unix:
perl -ne 'print unless m/^[\s-]$/' <infile.txt >outfile.txt

windows:
perl -ne "print unless m/^[\s-]$/" <infile.txt >outfile.txt
Avatar of nalanbar

ASKER

I ran the script, but the output still has the dashes...
Avatar of Suhas .
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
ASKER CERTIFIED SOLUTION
Avatar of wlfs
wlfs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial