The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to locate servers ibroxy Shell Programming and Scripting 5 05-30-2008 03:54 AM
3 servers 1 .ksh script cml2008 UNIX for Dummies Questions & Answers 2 01-20-2008 04:23 PM
csplit not behaving badg3r UNIX for Advanced & Expert Users 2 05-25-2006 06:36 AM
Script behaving differently in Crontab.. newtoxinu Shell Programming and Scripting 4 10-01-2004 01:22 PM
Script behaving differently in Crontab.. newtoxinu UNIX for Advanced & Expert Users 1 09-30-2004 04:00 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-13-2006
mhssatya mhssatya is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 57
Script behaving differently on two servers

All,

I have a script that runs on 2 servers and there seems to be something wrong. It's producing different results on the 2 servers.

Here is the script on server1 which is behaving correctly but on 2 behaving differently.
[QUOTE]
Quote:
awk 'FNR != 1 {


data[NR] = $0
out=FILENAME ".new"
file[NR]=out
records[out]=NR

}

END {
for ( r in records ) {
r_count=-1
for ( j in file ) {
if ( file[j] == r ) {
r_count++
}
}
if ( r_count != data[records[r]]) {
printf "Record count error in : %s\n", substr(r, 0, length(r)-3)
exit(1);
}
}
for ( i in file ) {
if ( i != records[file[i]] ) {
print data[i] > file[i]
}
}
close(file[i])
close(complete_file)
}
' $files
2nd server:

Quote:
awk 'FNR != 1 {


data[NR] = $0
out=FILENAME ".new"
file[NR]=out
records[out]=NR

}

END {
for ( r in records ) {
r_count=-1
for ( j in file ) {
if ( file[j] == r ) {
r_count++
}
}
if ( r_count != data[records[r]]) {
printf "Record count error in : %s\n", substr(r, 0, length(r)-3)
exit(1);
}
}
for ( i in file ) {
if ( i != records[file[i]] ) {
print data[i] > file[i]
}
}
close(file[i])
close(complete_file)
}
' $files
#done
I couldn't make out whats the error is? Please help
  #2 (permalink)  
Old 09-13-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
questions

What is the result you expect and what is the o/p you get? What are the input files like? And what errors, if any, do you get? Its very difficult to make a guess. What Unix runs on both servers?
  #3 (permalink)  
Old 09-13-2006
mhssatya mhssatya is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 57
The script checks a file and then writes the data rows to the new file.

The file will be like this format

Header
Data
Conut of data rows

If the data rows equals the last row in the file which is Count of data rows
then the script writes the data rows to a new file with .new extension appended to the original file.

sample output in debug mode from the code2 which is having problem. The 1st code doesn't throw any error and it's working correctly.

Quote:
+ awk FNR != 1 {


data[NR] = $0
out=FILENAME ".new"
file[NR]=out
records[out]=NR

}

END {
for ( r in records ) {
r_count=-1
for ( j in file ) {
if ( file[j] == r ) {
r_count++
}
}
if ( r_count != data[records[r]]) {
printf "Record count error in : %s\n", substr(r, 0, length(r)-3)
exit(1);
}
}
for ( i in file ) {
if ( i != records[file[i]] ) {
print data[i] > file[i]
}
}
close(file[i])
close(complete_file)
}
AUD01_CARE_DLY_20060912.dat
Record count error in : AUD01_CARE_DLY_20060912.dat.
The count in the file is correct but for some unkonwn reason it's showing error.

The code on 1 runs on HP-UX
and code on server 2 runs on SUNos
  #4 (permalink)  
Old 09-13-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
use nawk

Use nawk on Sun OS. I am not sure though if that solves your problem..
  #5 (permalink)  
Old 09-13-2006
mhssatya mhssatya is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 57
Awesome!!!!!

Perfect. But why is this different behavior on different boxes?
  #6 (permalink)  
Old 09-13-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
flavours of awk

You have different flavors of awk given by the HP & Sun. I havent worked on Sun OS but if you search this forum, there are similar issues encountered.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0