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 > 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
Checking the Empty line in csv file sollins Shell Programming and Scripting 4 05-15-2008 07:48 AM
Error checking a file from previous file size stuck1 Shell Programming and Scripting 2 12-06-2007 08:39 AM
Checking file size of zip file skwyer UNIX for Dummies Questions & Answers 2 10-11-2007 11:51 AM
Help with checking file size ssmith001 Shell Programming and Scripting 15 09-08-2005 09:48 PM
Checking file size jkuchar747 UNIX for Dummies Questions & Answers 2 03-02-2005 02:34 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 03-22-2007
kiran1112 kiran1112 is offline
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 04:48 AM..
  #2 (permalink)  
Old 03-22-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 574
Give a try on this..

Quote:
awk -F" " 'NR==1 {print $1}' filename
Thnx.Dennis
  #3 (permalink)  
Old 03-22-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
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 04:45 AM.. Reason: should be $2
  #4 (permalink)  
Old 03-22-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 574
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
  #5 (permalink)  
Old 03-22-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
how about this,

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

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
sed -n -e "s/^ *\([^ ]*\) *.*_error.*/\1/p;q" /home/user/temp.log
  #7 (permalink)  
Old 03-22-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Quote:
Originally Posted by matrixmadhan
how about this,

Code:
ls -l `awk -F" " 'NR == 1 { print $2; exit }' file` | awk '{ print 5 }'

should have been,
Code:
ls -l `awk -F" " 'NR == 1 { print $2; exit }' file` | awk '{ print $5 }'
oops! ' $ ' is missing
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 01:13 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