- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Finding and correcting curropt file lines
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:37 AM
08-21-2003 08:37 AM
Finding and correcting curropt file lines
HDR
POL
OBJ
I have a script which searches the file and errors if one of the lines has is corrupt. The scripts run as follows
cat
do grep -n -e "^HDR" -e "^POL" -e "^OBJ" -v > err_log.txt
done
I then manually edit the script at the lines reported in the err_log.txt (if any exist)
Is there any way I can get the script to perform the corrections for me? any help appreciated
Declan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:41 AM
08-21-2003 08:41 AM
Re: Finding and correcting curropt file lines
i think that you have no luck, because corruption can have different method for appearing.
If you know exactly what kind of corruption can be, there are chances.
Other way, if you want to tear away the offending lines, you can use a nice grep like your, without "-v", redirecting output to a file, but i suspect some missing things.
Any more hints from you regarding the kind of corruption ?
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:44 AM
08-21-2003 08:44 AM
Re: Finding and correcting curropt file lines
You havnt said what to replace with. Corruption is random. If you want you can redirect all the valid lines to another file but you may be missing the corrupted lines which needs your manual attention.
-Umapathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:47 AM
08-21-2003 08:47 AM
Re: Finding and correcting curropt file lines
HDR
POL
OBJ
I then go to offending line (end of HDR line) and hit Ctrl J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:50 AM
08-21-2003 08:50 AM
Re: Finding and correcting curropt file lines
I guess your 'grep' is already doing the trick if you remove -n and -v.
Or use this shorter solution:
grep -E "^(HDR|POL|OBJ)"
Erik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:51 AM
08-21-2003 08:51 AM
Re: Finding and correcting curropt file lines
Hi
use sed command for delete/change this lines.
To
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 08:51 AM
08-21-2003 08:51 AM
Re: Finding and correcting curropt file lines
cat $yourFile |
while read line
do
case $line in
HDR*) if corrupt ;then
fix
fi
print fixedLine;;
POL*) if corrupt ;then
fix
fi
print fixedLine;;
OBJ*) if corrupt ;then
fix
fi
print fixedLine;;
*) print $line;;
done > newFile
#check your fixes or
mv newFile yourFile
your have to put in how to test for corruption
and what the fix would be
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2003 09:18 AM
08-21-2003 09:18 AM
Re: Finding and correcting curropt file lines
cat yourFile|
awk '
#assume the first line starts correct
#print it without a newline
NR == 1 {printf("%s",$0);next;}
# if the line match our pattern
# apply the newline and
#print it without a newline
/^HDR/ {printf("\n%s,$0);next;}
/^POL/ {printf("\n%s,$0);next;}
/^OBJ/ {printf("\n%s,$0);next;}
# doesn't match one of out patterns
# print the line, joining it to the
# previous line
{printf("%s,$0);}
# apply an ending newline if necessary
END {printf("\n");}
'> newfile
you can apply spacing on the join and ending newline as desired
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 12:44 AM
08-22-2003 12:44 AM
Re: Finding and correcting curropt file lines
awk: The string
%s,$0);ne cannot contain a newline character.
The source line is 13.
The error context is
/^HDR/ {printf("\n%s,$0);next;} >>>
<<<
syntax error The source line is 14.
awk: The statement cannot be correctly parsed.
The source line is 14.
awk: There are 3 missing } characters.
awk: There are 3 missing ) characters.
./test_and_fix[15]: Syntax error at line 15 : `(' is not expected.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 02:24 AM
08-22-2003 02:24 AM
Re: Finding and correcting curropt file lines
cat yourFile|
awk '
#assume the first line starts correct
#print it without a newline
NR == 1 {printf("%s",$0);next;}
# if the line match our pattern
# apply the newline and
#print it without a newline
/^HDR/ {printf("\n%s",$0);next;}
/^POL/ {printf("\n%s",$0);next;}
/^OBJ/ {printf("\n%s",$0);next;}
# doesn't match one of out patterns
# print the line, joining it to the
# previous line
{printf("%s",$0);}
# apply an ending newline if necessary
END {printf("\n");}
'> newfile
One day or the other i will study awk seriusly....
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 02:38 AM
08-22-2003 02:38 AM
Re: Finding and correcting curropt file lines
awk: Cannot find or open file match.
The source line number is 17.
./test_and_fix[15]: Syntax error at line 15 : `(' is not expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 02:52 AM
08-22-2003 02:52 AM
Re: Finding and correcting curropt file lines
The following perl script will do what you expect :
#!/usr/bin/perl
# read the file and place it in a list
while (<>) {
chomp;
push(@liste,$_);
}
# print first line assumed ok
$line = shift(@liste);
print $line;
# handle other lines
foreach $line (@liste) {
# print a newline if the line did not match the patterns
print "\n" if ($line =~ /^HDR/ || $line =~ /^POL/ || $line =~ /^OBJ/);
print $line;
}
# print trailing newline
print "\n"
Save the script in a file xx.pl (eventually change the first line to match the path of a perl interpreter on your system), make the xx.pl file executable and use :
cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 03:49 AM
08-22-2003 03:49 AM
Re: Finding and correcting curropt file lines
I'm going to get onto my boss and sort out a perl course!
Great stuff and thanks again! I'll be able to relax over the weekend
Have a good one
Declan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2003 07:05 AM
08-22-2003 07:05 AM
Re: Finding and correcting curropt file lines
Massimo has pointed out my missing
double qoutes in the printf's
and
you might already satisfied with Charles's
perl script.
but it still looks like there was a syntax
issue with your script before that. If your
still interested in finding out what it was,
if you'd post your verison, i'm sure we can
figure out where the problem is.