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 and shell scripting languages 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 07:00 AM
Unix Shell Scripting premamadhuri Shell Programming and Scripting 4 11-05-2007 03:31 AM
Shell Scripting (Unix) tt1ect Shell Programming and Scripting 3 04-15-2007 10:15 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 09:12 AM
Unix shell scripting la_burton UNIX for Dummies Questions & Answers 6 10-22-2004 12:41 PM

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

Join Date: May 2006
Posts: 1
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 07:12 AM.. Reason: To give clear view of the problem
  #2 (permalink)  
Old 05-22-2006
d_swapneel14 d_swapneel14 is offline
Registered User
  
 

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

cheers
swapneel
  #3 (permalink)  
Old 05-22-2006
jsandova's Avatar
jsandova jsandova is offline
Registered User
  
 

Join Date: May 2006
Location: Burbank Ca
Posts: 28
No but why don't you post an example of what you are doing so we can try to isolate issue or replicate it.
  #4 (permalink)  
Old 05-22-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
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.
  #5 (permalink)  
Old 05-23-2006
azrealhk azrealhk is offline
Registered User
  
 

Join Date: Jul 2002
Location: HK
Posts: 20
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
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 05:18 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