Header and trailer Check in UNIX

I am planning to automate multiple files through Unix script.

Could you please guide for making the automation for multiple files ?

Eg.

I have to check header and footer for all files in the particular path and the header pattern should match with the filename.

Filename- Filename.txt
Header - HEAD,filename.txt
1,Sumit,31,Delhi,,
2,Virat,33,Meerut,,
3,Amit,34,Jammu,,
Trailer -TRAIL,3

Also,I have to check header,trailer,file and header filename match,count check in trailer section,Total column check and not null check to automate the things.

I recommend coming up with something you've tried to move things along; otherwise, this seems a bit vague. For example, something like this....

find <particular-path> -name '*<some-common-pattern*' | while read a
do
filename_in_header=`head -1 ${a) | awk '{print $NF}'`
filename_in_trailer=`tail -1 {a} | awk '{print $NF}'`
.
.  <compare each of the above to the filename ${a} and then do whatever
.
done

This is just a simple example to illustrate what I mean by posting something you've tried.

1 Like

Correct.

We encourage all users at unix.com to post the code and scripts they have tried "on their own" and any error messages they got when they tried and failed.