File checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File checking
# 1  
Old 04-12-2011
File checking

Hi

I have 4 files, I need the check whether these 4 files are having header and Trailer records. header and trailer records are identified with 1,b. If any file is not having these we will not proceed with other process.

Output should be 1 if all files are having header and footer other wise it return 0.

Can anyone suggest me how to write the script
# 2  
Old 04-12-2011
Check those with the "head" and "tail" commands and then store in some variable/file say VAR=1
If anyone is missing, change the VAR=0.
# 3  
Old 04-12-2011
I need to parameterize the file names

---------- Post updated at 01:32 PM ---------- Previous update was at 08:42 AM ----------

I wrote this script:

Please provide some suggestions on this, i havent tested this. Output should be something which indicates the all files are proper. but not sure whether it works.

I am passing 4 file names in the command as arguements.
Code:
#!/bin/bash


Result=0
for f in $1 .. $4

do 

HValue=`cut -b 1 < $f | head -1`
TValue=`cut -b 1 < $f | tail -1`

if ["$HValue"=A] != ["$TValue" = Z]

then 
    echo $f doesnot have Header/Footer properly >>file.txt
    Result=$Result+1
else
    echo $Result
 
fi

done
echo $Result

---------- Post updated at 04:59 PM ---------- Previous update was at 01:32 PM ----------

can any body help me on this?

Last edited by Scott; 04-12-2011 at 03:36 PM.. Reason: Please use code tags
# 4  
Old 04-12-2011
You agreed not to bump posts when you registered here.

Code:
# $# is the number of arguments
while [ "$#" -gt 0 ]
do
        echo "Do something on $1"

        # Discard $1, move everything down one, $2 becomes $1 etc.
        shift
done

# 5  
Old 04-19-2011
I have create dthe unix script to check the file whether valid or not.

I have created the script. but it should be generic because no.of files and comparison value will be differenct(Eg:header identification number would 0 for some files and 1 for some file) for each process.

Can any body give some suggesions how we can do this. you can find the below script to check Quote:
Code:
#!/bin/bash 
set -x 
 
Result=0 
 
[ -f "$0.log" ] && > $0.log 
 
function log 
{ 
echo "$@" >> "$0.log" 
} 
 
for file in $1 $2 
 
do 
 
cd /informationserver/projects/project_Name/input/ 
if [ -f "$file" ] 
then 
if [ `grep "^[0]" $file | wc -l` = 1 ] 
then 
if [ `grep "^[9]" $file | wc -l` = 1 ] 
then 
Result=` expr $Result + 0` 
else 
Result= ` expr $Result + 1` 
log There is No Trailer in $file 
fi 
else 
if [ `grep "^[9]" $file | wc -l` = 1 ] 
then 
Result=` expr $Result + 1` 
log There is No Header in $file 
else 
Result=` expr $Result + 1` 
log There is No Header&Trailer in $file 
fi 
fi 
else 
log No $file exists in the directory. 
Result=` expr $Result + 1` 
fi 
 
done 
 
echo $Result

Moderator's Comments:
Mod Comment Please use code tags when posting script listings, ...

Last edited by pludi; 04-19-2011 at 08:18 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

2. Shell Programming and Scripting

Awk: File Checking Issues with 9 multiple file

Hi, I have 9 files which are generated dynamically & if there is a some condition which doesn't meet the criteria then file is not created or is of zero size. so further i am unable to consolidate the files based on following code 1 awk -F, -v ptime="201407" 'FNR==1... (3 Replies)
Discussion started by: siramitsharma
3 Replies

3. Shell Programming and Scripting

File checking

Hello Experts, File contains 5 columns with | delimeter. 1,3,5 columns are required columns means it should contains values. reset of the columns it will contain value or not. test1.txt: a@a.com|a|b|c|d |a|b|c|d output: test2.txt a@a.com|a|b|c|d I need the unix script, read the... (5 Replies)
Discussion started by: muralikri
5 Replies

4. UNIX for Advanced & Expert Users

File checking

Hello Experts, File contains 5 columns with | delimeter. 1,3,5 columns are required columns means it should contains values. reset of the columns it will contain value or not. test1.txt: Code: a@a.com|a|b|c|d |a|b|c|d output: test2.txt Code: a@a.com|a|b|c|d I need the unix... (1 Reply)
Discussion started by: muralikri
1 Replies

5. UNIX for Dummies Questions & Answers

Checking for same file name

I was wondering if there is a way to to check if two files are the same. I've tried writing a script called samefile, which takes in two arguments (files) and attempts to compare them to see if they're the same file. Here is what I have so far: if then echo "The two files are not the... (4 Replies)
Discussion started by: Trinimini
4 Replies

6. Shell Programming and Scripting

Script check for file, alert if not there, and continue checking until file arrives

All, Is there a way to keep checking for a file over and over again in the same script for an interval of time? Ie If { mail -user continue checking until file arrives file arrives tasks exit I don't want the script to run each time and email the user each time a file... (4 Replies)
Discussion started by: markdjones82
4 Replies

7. Shell Programming and Scripting

file checking

Hi I need to check the file,if file exist ,do some other opearations and make it successful. If file does not exist skip all steaps,go to last step and make it succesful.below is scripts is working for file exist but its not working for file not exist ... (0 Replies)
Discussion started by: mohan705
0 Replies

8. Shell Programming and Scripting

Checking for a control file before processing a data file

Hi All, I am very new to Shell scripting... I got a requirement. I will have few text files(data files) in a particular directory. they will be with .txt extension. With same name, but with a different extension control files also will be there. For example, Sample_20081001.txt is the data... (4 Replies)
Discussion started by: purna.cherukuri
4 Replies

9. Shell Programming and Scripting

Multiple file existence and checking file size

I want to check the files in particular directory are more that 0 Bytes i.e, Non zero byte file. The script should print a msg if all the files in that directory are empty( 0 Byte). (2 Replies)
Discussion started by: lathish
2 Replies

10. Shell Programming and Scripting

Error checking a file from previous file size

Hi, I'm currently trying to write a script that checks a log file for certain errors. Once checked it then records the filesize in another file. All this is fine, my problem is that the next time I do my error check I only want to check from previously recorded filesize to the end of file. I'm... (2 Replies)
Discussion started by: stuck1
2 Replies
Login or Register to Ask a Question