The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need your Help on Unix Shell Scripting......... vinayraj UNIX for Advanced & Expert Users 5 02-08-2008 03:00 AM
Unix Shell Scripting premamadhuri Shell Programming and Scripting 4 11-04-2007 11:31 PM
Shell Scripting (Unix) tt1ect Shell Programming and Scripting 3 04-15-2007 06:15 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
Unix shell scripting la_burton UNIX for Dummies Questions & Answers 6 10-22-2004 08:41 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2006
Registered User
 

Join Date: May 2006
Posts: 1
Stumble this Post!
Unix shell scripting

Hi,

we are writing this fields dynamically retrieved from database and writing
into the file.



$bmpRec = $bmpRec.'|'.$cust_id; # sp4

$bmpRec = $bmpRec.'|'.$serv_id; # sp5

$bmpRec = $bmpRec.'|'.$site_id; # sp6

$bmpRec = $bmpRec.'|'.$loc_id; # sp7

$bmpRec = $bmpRec.'|'.substr($si_room, 0, 25); # sp8

$bmpRec = $bmpRec.'|'.substr($floor, 0, 9); # sp9

$bmpRec = $bmpRec.'|'.substr($sof_id, 0, 20); # sp10

$bmpRec = $bmpRec.'|'.substr($cc_case_num, 0, 10); # sp11

$bmpRec = $bmpRec.'|'.substr($cc_part_num, 0, 30); # sp12

$bmpRec = $bmpRec.'|'. ""; # sp13, (cc_site_id) 01d removed from db

$bmpRec = $bmpRec.'|'.substr($acc_type, 0, 20); # sp14

$bmpRec = $bmpRec.'|'.$speed_value; # sp15

$bmpRec = $bmpRec.'|'.substr($link_protocol, 0, 10); # sp16

$bmpRec = $bmpRec.'|'.$site_glbl_dlci; # sp17

$bmpRec = $bmpRec.'|'.$intnl_gw_popid; # sp18

$bmpRec = $bmpRec.'|'.substr($fr_encapsulation, 0, 10); # sp19

$bmpRec = $bmpRec.'|'.substr($csu_dsu, 0, 25); # sp20

$bmpRec = $bmpRec.'|'. ""; # sp21 (lpw)


Finally we are printing the $bmpRec to a file
printf OUT "$bmpRec|\n"

When we are printing this variable into the file it has printed upto
I # sp9 and also it has not printed the final new line character (\n)
after this a shell script will append a trailer record (TRLR|727)with
the total number of records in the file.
Because the last record was half printed we are getting the trailer
record on the same line (appended to the last record) as follows

USP|200605|2212404|5314|15|880863|661897|CABL PLNT|1||TRLR|727|

Last edited by Maruthi Kunnuru; 05-23-2006 at 03:12 AM. Reason: To give clear view of the problem
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-22-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
Stumble this Post!
hi
i never seen wrong output.
but wht is your excat case??

cheers
swapneel
Reply With Quote
  #3 (permalink)  
Old 05-22-2006
jsandova's Avatar
Registered User
 

Join Date: May 2006
Location: Burbank Ca
Posts: 27
Stumble this Post!
No but why don't you post an example of what you are doing so we can try to isolate issue or replicate it.
Reply With Quote
  #4 (permalink)  
Old 05-22-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Stumble this Post!
Sometimes the line count from wc -l is short by one line, but only if the last line is incomplete because it does not end with a new line character.
Reply With Quote
  #5 (permalink)  
Old 05-22-2006
Registered User
 

Join Date: Jul 2002
Location: HK
Posts: 20
Stumble this Post!
I have seen ls, wc etc give false readings if the file is opened by another program which is writing to it.

if the output is not flushed then file size etc remains the same.
try....

# cat flush.pl
#!/usr/local/bin/perl
open FH, ">flush.txt";
for (1..410) {
print FH "abcdefg89\n";
}
sleep 360;
close FH;

NOTE: The string is 10 chars (including \n), 410 lines written before sleep. therefore size should be 4100 bytes. The file is already open and not close yet on the sleep.

# tail flush.txt
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdefg89
abcdef

The block size of our system is 4096 so instead of 4100 bytes, 4096 is seen. The tail command will only show upto 4096 bytes.

# ls -l flush.txt
-rw-r--r-- 1 root system 4096 May 23 12:06 flush.txt

Ls confirms only 4096 bytes is seen

# wc -l flush.txt
409 flush.txt

wc -l shows only 409 and note 410.

The file will only show 4100 when you close the file.

# ls -l flush.txt
-rw-r--r-- 1 root system 4100 May 23 12:18 flush.txt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0