Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message through email....

Status
Not open for further replies.

kumariaru

IS-IT--Management
Mar 9, 2006
61
AU
Good Morning all,
I have a scenario where I need to handle 110 files. I have to get the count of lines of each file individually and need to send an email when the count of the file is 2.
I want to do it in a single script.
For Example:
FILE1 has two lines then I need to send a mail saying that the count of FILE1 is 2.
FILE2 count is more then 2 then no need to send a mail.
FILE3 count is two then I need to send a mail saying that the count of the FILE3 is 2.

Thank you....


 
Hi

One way could be
Code:
wc -l * 2> /dev/null | while read nr name; do test $nr -eq 2 && mutt -a "$name" -s "the count of the $name is 2" someone@example.com; done

Feherke.
 
Another way...
Code:
[ignore]wc -l * |sed -n 's/^  *//g;/^2 /p;'|cut -f2 -d' '|mailx -s "Files with two lines" someone@example.com
[/ignore]
 
Sam - If the line count is 20, will this command send an email or not?
 
Thank you Feherke and Sam...
I will check with both the scripts.....

 
No, the [tt]sed[/tt] is only allowing lines that start with '2 ' (two and a space). That's the [tt]'/^2 /p'[/tt] part.
 
Actually, I didn't meet the specs. My solution will send one email with a list of those files that have two lines each. If no files have two lines, an email still gets sent, but there will be no files listed in it.

 
Good Morning All,
I have a a problem with wc -l. When I am opening a file with in vi editor I can see 2 lines in it but when I am doing a "wc -l filename" I am getting only 1 as output. It is same with all the files.I am getting word count of total records -1.These files are in DOS format and are moved to UNIX server. I am not understanding why this is happening...

Thanks in advance...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top