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
Checking the Empty line in csv file sollins Shell Programming and Scripting 4 05-15-2008 04:48 AM
Error checking a file from previous file size stuck1 Shell Programming and Scripting 2 12-06-2007 04:39 AM
Checking file size of zip file skwyer UNIX for Dummies Questions & Answers 2 10-11-2007 08:51 AM
Help with checking file size ssmith001 Shell Programming and Scripting 15 09-08-2005 06:48 PM
Checking file size jkuchar747 UNIX for Dummies Questions & Answers 2 03-02-2005 10:34 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-21-2007
Registered User
 

Join Date: Mar 2007
Posts: 11
checking size of the first line ina file

Hi My test.log file looks like this:
Code:
   0 190_GSTV_HUX_003QISCGSK026_error070322_115331917.log
   34 190_GSTV_HUX_003QISCGSK026_error070117_151311385.log
   12 190_GSTV_HUX_003QISCGSK026_error070117_151230001.log
   2 190_GSTV_HUX_003QISCGSK026_error070117_101010001.log
   0 190_GSTV_HUX_003QISCGSK026_error070117_0832001254.log
   0 190_GSTV_HUX_003QISCGSK026_error070115_122813125.log
   3 190_GSTV_HUX_003QISCGSK026_error070115_115331917.log
   0 190_GSTV_HUX_003QISCGSK026_error070115_114442254.log
   0 190_GSTV_HUX_003QISCGSK026_error070112_1156001509.log
Now i need to write a script which checks for the size of the first log file
ie.,in this case the size of "190_GSTV_HUX_003QISCGSK026_error070322_115331917.log"
please note that the test.log will be updated everytime i run a script and only the part remains constant is '190_GSTV_HUX_003QISCGSK026_errorXXXXXX_XXXXXXXXX.log'

is there any cmd which checks for the size of the first line in the test.log file and give the result?using which i need to write a condition...

Presently i tried this:
Code:
check=`cat /home/user/test.log | awk '{print $1}'`
but it is giving the output as :
0 34 12 2 0 0 3 0 0

if i use the condition
Code:
if [ $check = 0 ]
i m getting error as "A test command parameter is not valid."
beacause check contains 0 32 12 2 .......

Please can some one help me in this regard???
Thanks in advance

Last edited by kiran1112; 03-23-2007 at 12:48 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-21-2007
dj -------
 

Join Date: Feb 2007
Location: Cochin, India
Posts: 322
Give a try on this..

Quote:
awk -F" " 'NR==1 {print $1}' filename
Thnx.Dennis
Reply With Quote
  #3 (permalink)  
Old 03-22-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,475
Quote:
is there any cmd which checks for the size of the first line in the test.log file and give the result?using which i need to write a condition...
Code:
awk -F " " '{ print length($2) }' filename

Last edited by matrixmadhan; 03-22-2007 at 12:45 AM. Reason: should be $2
Reply With Quote
  #4 (permalink)  
Old 03-22-2007
dj -------
 

Join Date: Feb 2007
Location: Cochin, India
Posts: 322
Quote:
Originally Posted by matrixmadhan
Code:
awk -F " " '{ print length($2) }' filename
Hi Matrix,

Seems like this thread is a continuation of the below thread...I think he is not looking for the size of the second field.....rather, the first field which is the size of the file..

script to check for a condition inside a file
Reply With Quote
  #5 (permalink)  
Old 03-22-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,475
how about this,

Code:
ls -l `awk -F" " 'NR == 1 { print $2; exit }' file` | awk '{ print 5 }'
Reply With Quote
  #6 (permalink)  
Old 03-22-2007
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Code:
sed -n -e "s/^ *\([^ ]*\) *.*_error.*/\1/p;q" /home/user/temp.log
Reply With Quote
  #7 (permalink)  
Old 03-22-2007
Registered User
 

Join Date: Mar 2007
Posts: 11
Hi all
many thanks for all your suggestions
but none of the commands is able to give the size of only the first line.
the following cmds
Code:
awk -F" " 'NR=1{print $1}' test.log
and 
sed -n -e "s/^ *\([^ ]*\) *.*_error.*/\1/p;"  test.log
and
 ls -l `awk -F" " 'NR == 1 { print $2; exit }' test.log` | awk '{ print 1 }'
gives the first column for all the files...but i only need for the first one

any help is appreciated
Thanks
Kiran
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:34 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