How to check the file size and content of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check the file size and content of the file
# 1  
Old 07-18-2011
How to check the file size and content of the file

Hi,

I have a text file in the below format.
Code:
$cat my_paramater_file.txt
'
[FOLDER_NAME.WF:wf_my_workflow.ST:S_my_session]
$$ETL_EXTRACT_DATE=07/17/2011 17:55:05.000000
'
$

Would like to write script based on the below requirements.

1. The file should not be 0 byte.
2. The content of the file should be 4 lines and the ETL_EXTRACT_DATE field should contain the date and time values.
3. If the file is 0 byte or there is no value for the ETL_EXTRACT_DATE field then it should send an alert message.

Could you please help me how to write a script base don above requirements.

Last edited by Scott; 07-18-2011 at 10:39 AM.. Reason: Code tags
# 2  
Old 07-18-2011
Hi,

If u want, then need to do some modifications in below script and use...
Code:
clear
echo -n "Enter the name of file : "
read name
echo "Checking the existance of file $name"
echo
echo ".................................................."
sleep 2
ls -lrt $name
echo "Checking the size of file"
echo
sleep 2
size=`ls -lrt $name | awk '{print $5}'`
echo "******Size of $name is $size bytes"
echo
sleep 2
echo "Checking the number of lines"
echo
sleep 2
line=`wc -l $name | awk '{print $1}'`
echo "******$name is containing $line lines"
echo
sleep 2
echo "Checking the value of ETL_EXTRACT_DATE"
echo
sleep 2
value=`cat $name | grep ETL_EXTRACT_DATE | sed 's/\(.*\)=\(.*\)/\2/'`
echo "******Value of ETL_EXTRACT_DATE is $value"
echo
sleep 2
if [ $size == 0 -o  $value ==  ]
then
  echo "the file is 0 byte or there is no value for the ETL_EXTRACT_DATE field .."
fi


Last edited by Scott; 07-18-2011 at 10:41 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check specific content from log file

Hi all, i have a logfile which is continuously being updated. I have built a script to check for a specific content and if it is found, it sends a string into a file. Here's the current script: #!/bin/bash logfile=/opt/jboss-eap-6.3/standalone/log/server.log tail -fn0 $logfile | \... (7 Replies)
Discussion started by: nms
7 Replies

2. UNIX for Beginners Questions & Answers

How to get script to create a new file that lists folder content sorted by size?

I have a script that sorts and processes unsorted files to newly created directories. Its working great, but I am trying to understand the leanest method to get the script to create an additional file within each newly created directory that: Contains a list of all files in the directory... (4 Replies)
Discussion started by: Braveheart
4 Replies

3. Shell Programming and Scripting

File size check

I am trying to check whether two files are empty or not using below if condition but its checking for only one file if ] Again I tried if && ] Need your assistance (2 Replies)
Discussion started by: Aditya_001
2 Replies

4. Shell Programming and Scripting

Check a file size

I'm doing a script thats check if mylogfile.log is bigger then 5000 but i dont know how to write it. thanks in avance. (6 Replies)
Discussion started by: Froob
6 Replies

5. Shell Programming and Scripting

Check content of file

Hi All, I m very new to unix...i jus want to chk the content of file. ma requirement is if file has a content then display it else dont display or something pls specify which loop shalli use either for or while?? (20 Replies)
Discussion started by: navsan
20 Replies

6. Shell Programming and Scripting

check the file size

if ; then cp /tmp/testfolder/*.* ~/new/logs/ else echo "No files today" exit fi The problem is this doen't work when there is more than 1 file. Please tell me how to take the latest file and check the size of the file in a directory (1 Reply)
Discussion started by: sandy1028
1 Replies

7. Shell Programming and Scripting

Check the file size - help

I want to write a batch job (ksh) with the following requirement we have file feeds coming to our system from other team, if the file size is greater than expected then we dont need to process the file for the day and need to archive the file and send email notification to the manager saying... (5 Replies)
Discussion started by: sithara
5 Replies

8. Shell Programming and Scripting

Check file content type

I have a shell script that takes a file and uses "syncsort" to sort contents. I want to add a condition to check whether the input file is textual or binary format. If textual, the "syncsort" will be used to sort the files contents. Otherwise, the sorting process will be skipped. Note that the... (3 Replies)
Discussion started by: synthea
3 Replies

9. Shell Programming and Scripting

To check the content of one file in another

Hi , I have a file called "X" . the content of X are X -- abc def and i have a file called "Y" , the content of Y are Y -- erty sdss s abc sfs def I need to check if the content of file X is contained in Y.Only unix (7 Replies)
Discussion started by: giri_luck
7 Replies

10. Shell Programming and Scripting

To check file size

Hi All, I am in small problem.. i have one script which transfers some big files to my ftp usign normal command like put .... my problem is how to check whether my file have been transferred successfully on ftp or not... i know only inside ftp we have option like 'size' command which... (2 Replies)
Discussion started by: Shahul
2 Replies
Login or Register to Ask a Question