how to view last line of multiple files

Dear All,

can anybody help me out in generating a command that can be used to view the last line of multiples files.

e.g:

file 1 contains 100 records
file 2 contains 200 records
file 3 contails 300 records

now i need a command that can be used to display the last line of each file. (i.e. file 1 file 2 & file 3)

an urgent reply in this regard will be highly appreciated.:b:

How about

$ tail file1 file2 file3
#!/bin/ksh
for filename in "file 1" "file 2" "file 3"
do
         # If there is anything in the file, show which file and the last line
         if [ -s "${filename}" ]
         then
                 ls -lad "${filename}"
                 # tail hyphen one shows the last line
                 tail -1 "${filename}"
                 echo ""
         fi
done

hi methyl,

thankz for the reply,

please advice that a folder contains more than 100 files and each files contains 1000 records. All files have a (.txt) extension. Now please help me out from this prespective.

Thanks in advance.

Really should be a new post. Here is a variant on my previous post for any number of text files in the current directory. Hope this helps.

#!/bin/ksh
ls -1 *\.txt 2>/dev/null | while read filename
do
         # If there is anything in the file, show which file and the last line
         if [ -s "${filename}" ]
         then
                 ls -lad "${filename}"
                 # tail hyphen one shows the last line
                 tail -1 "${filename}"
                 echo ""
         fi
done

thankz a million methyl,

now please guide me in knowing the logic for this script line by line if possible.

Thankz in advance.:b:

Hre we go. I have inserted comment lines which may help. However if you see a command you need to know more about use "man <command>".

#!/bin/ksh
# The above line forces Korn Shell. It could equally be bash.
#
# ls hyphen one lists the names of files and directories in the current directory
# We have assumed that there are no directory names ending in ".txt"
# The "2>/dev/null" redirects the error channel 2 to a black hole so
# the script does not fail if we have no files in the directory.
# The next line places the list of filenames onto a pipeline for processing.
# The "\." escapes the full stop such that we definitely get a fulll stop (this is unix not MSDOS).
ls -1 *\.txt 2>/dev/null | while read filename
do
         # If there is anything in the file, show which file and the last line
         # "if -s" tests whether the file exists and has any size
         if [ -s "${filename}" ]
         then
                 # "ls -lad" lists the file and does not go deeper down a tree
                 ls -lad "${filename}"
                 # tail hyphen one shows the last line
                 tail -1 "${filename}"
                 # Just output a blank line for ease of reading the output
                 echo ""
         fi
done

so nice of ya, i really helped me out...

thanks once again....

cheers:)