• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Delimiter file

I have .txt file with | (pipe) delimiter in AIX 5.2

If the very first column (before the 1st delimiter) is blank, I need to remove the entire row.
The pattern is xxx|hh:mm:ss tt| to begin with.

G16|07:15:00 AM|SURGERY|IPSIX|1520867|56||01:15:00 AM|31613-TRACHEOSTOMA REVISION; SIMPLE, WITHOUT FLAP ROTATION|bla………. ROTATION||||||||||31613.000000||||||||||||||||||||||||16526467||
||

G14|07:15:00 AM|SURGERY|PEDTWO|1520884|17Y||04:00:00 AM|54550-EXPLORATION FOR UN
DESCENDED TESTIS (INGUINAL OR SCROTAL AREA)|bla…………54550.000000||||||||||||||||||||||||165
17542|17167991|||

T03|07:30:00 AM|QUANTIM|CHUCK|1520587|46||02:00:00 AM|31613-TRACHEOSTOMA REVISION; SIMPLE, WITHOUT FLAP ROTATION| bla…..


T04|07:30:00 AM|QUANTIM|RITA|1520678|6 months||11:00:00 AM|43280-LAPAROSCOPY, SURGICAL, ESOPHAGOGASTRIC FUNDOPLASTY (EG, NISSEN, TOUPET PROCEDURES)|bla……

T05|07:30:00 AM|QUANTIM|WILMA|1520673|39||00:30:00 AM|10060-INCISION AND DRAINAGE OF ABSCESS; SIMPLE OR SINGLE|bla……SINGLE||||||||||10060.000000||||||||||||||||||||||||15544367||||

T02|07:30:00 AM|SURGERY|DOEONE|1520900|106|TRU TRU Pre Arv Doe TRU Pre Arv Doe|05:00:00 AM|61537-CRANIOTOMY W/ELEVATION BONE FLAP; LOBECTOMY TEMPORAL LOBE W/O EMD|||||||ICU Bed||05/08/2006|NEUROSURGER ….

It the row is completely blank, I need to remove the row as well.

After removing rows, I need to save the file cleaned into a new .txt file.

How to do?
0
JohnLucania
Asked:
JohnLucania
3 Solutions
 
star_trekCommented:

open(FILE1,"<in.txt");
open(FILE2,">out.txt");
while(<FILE1>) {
     chomp;
     if($_ =~ /^[\w|\d]{3}|\d{2}:\d{2}:\d{2} \w{2}/) {
           print FILE2 $_."\n";
     }
}
close(FILE1);
close(FILE2);
0
 
JohnLucaniaAuthor Commented:
delimeter.pl: 0403-057 Syntax error at line 1 : `(' is not expected.

What am I missing here??

root:stmil1:/home/cdi> cat delimeter.pl
open(FILE1,"<in.txt");
open(FILE2,">out.txt");
while(<FILE1>) {
     chomp;
     if($_ =~ /^[\w|\d]{3}|\d{2}:\d{2}:\d{2} \w{2}/) {
           print FILE2 $_."\n";
     }
}
close(FILE1);
close(FILE2);
0
 
JohnLucaniaAuthor Commented:
oopps..!  
forgot to put:  
#!/usr/bin/perl -w
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
star_trekCommented:
you should do
perl delimiter.pl
not cat delimiter.pl
 also in the first line add
#!/usr/bin/perl

so the code is (i am assuming in.txt is the input file)

#!/usr/bin/perl
open(FILE1,"<in.txt");
open(FILE2,">out.txt");
while(<FILE1>) {
     chomp;
     if($_ =~ /^[\w|\d]{3}|\d{2}:\d{2}:\d{2} \w{2}/) {
           print FILE2 $_."\n";
     }
}
close(FILE1);
close(FILE2);
0
 
ozoCommented:
perl -pe "s/^(\|.*)?\n//" <file.txt > new.txt
0
 
ahoffmannCommented:
# not as elegant as perl, but ...
awk -F'|' '(NF<1){next}($1==""){next}{print}' file.txt

BTW, ozo you're using double quotes which might cause some unexpected behaviour in some shells
0
 
JohnLucaniaAuthor Commented:
great!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now