Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing extracted data to same line of file 2

Status
Not open for further replies.

siswjh

MIS
Dec 6, 2001
63
US
I have a script that extracts data. I want the data that it extracts to be printed on the same line. I can't seem to make it work. It extracts the data but prints each find on a new line. The data that is being extracted also has to be delimited by a semi-colon. Here is the script.
Code:
#!/usr/local/bin/perl -w

use Date::Manip;
$date=&ParseDate("Fri Jan 9");
$date=~ s/^(.{4})(.{2})(.{2})..:..:..$/$1-$2-$3/;

$file = "/u01/home/siswjh/logfile";
chdir("/u01/home/siswjh/appworx")|| die "can't cd to appworx :!";
opendir(APPWORX, "/u01/home/siswjh/appworx") or die "can't open directory :!";
foreach $name (readdir (APPWORX)){
next unless -f $name;
chomp $name;
open(FILE, "$name") || die "can't open $name for reading: $!";
open(OUT, ">>$file") || die "can't open $file for writing: $!";
while (<FILE>) {
if (/HSCSUNP1/) {
print OUT &quot;$_;$date;&quot;;
#print OUT $date;
}
}
}
And here is the out put I get.

Operator HSCSUNP1
;2004-01-09;
 
try chomping $_ like this?

while (<FILE>) {
[red]chomp;[/red]
if (/HSCSUNP1/) {
print OUT &quot;$_;$date;&quot;;
#print OUT $date;
}



Kind Regards
Duncan
 
Hey duncdude, that worked but I have one more question. When it puts the extracted data in the new text file it does not take the first value extracted and left justify it. It looks like there is probably 8 or 10 spaces. Do you have any idea how to do away with that.
 
Use a regex to strip of the beginning space
if (/HSCSUNP1/) {
s/^\s+?//;
print OUT &quot;$_;$date;&quot;;
#print OUT $date;
}
 
blimey I just blinked and raklet had already answered it... cool!


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top