Split-Email-removing files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Split-Email-removing files
# 1  
Old 01-30-2006
Data Split-Email-removing files

Friends,

I have a datafile that have unknown a number of CHARACTERS.

if the datafile have more than 1 character and less than 20
email me the file
rm datafile

if the datafile have more than 20 characters
split the datafile into 20 characters in each file
email datafileaa
email datafilebb ....and/or so on
rm datafileaa datafilebb .....so on

I have problems with of knowing how many files there will be if the datafile > 20 characters and how to email these file and remove them.

Thanks!
# 2  
Old 02-01-2006
Simple IF the file in question has one line only - the split command will cut up a file incorrectly if there are multiple lines versus one line.

test file contains:
abcdefghijklmnopqrstuvwxyz1234567890123456789

Code:
#!/bin/csh -f
#
# Leave it to you to do other checking (like if the file actually exist)
#
# Get the number of characters in the file name junk
set num=`wc -c ./junk|awk '{print $1}'`
if ("$num" < 21) then
        # email and remove file
        mailx -s"file had 20 or less characters" myaccount@mydomain.com < ./junk
        rm ./junk
else
        # cut file into separate files of 20 characters
        # Note 'myjunk' - use something that will allow you to list ONLY those
        #  files to allow the foreach command to work AND to insure the remove
        # is only going to remove the files you want deleted
        split -b20 junk myjunk
        set junkfiles=`ls -1 myjunk*`
        foreach x ($junkfiles)
        mailx -s"$x" myaccount@mydomain.com < $x
        end
        rm myjunk*
endif

# 3  
Old 02-01-2006
I will try it! many thanks!
# 4  
Old 02-01-2006
I don not want to email out a file with no character. I may have a file of zero byte or what whatever bytes.

will :

if ("$num" < 21) then

be

if ("$num" < 21) then

if (1 < "$num" < 21) then

Work??? Can I have this syntax?

Thanks!
# 5  
Old 02-02-2006
MySQL

I go everything works! Great codes!!!!

Many thanks!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. UNIX for Beginners Questions & Answers

Find and removing the old files and zipping the files using shell script

Hi, I am trying to removing the old files which were older than 10 days and same g zipping the files using the shell script. script was return as follows. find /jboss7_homes/JBOSS7/SKYLIV??/SKYLIV??_CRM/jboss-eap-7.0/standalone/log -mtime +10 -type f | xargs rm -f find /cer_skyliv??/log... (6 Replies)
Discussion started by: venkat918
6 Replies

3. UNIX for Beginners Questions & Answers

Split and Rename Split Files

Hello, I need to split a file by number of records and rename each split file with actual filename pre-pended with 3 digit split number. What I have tried is the below command with 2 digit numeric value split -l 3 -d abc.txt F (# Will Produce split Files as F00 F01 F02) How to produce... (19 Replies)
Discussion started by: techedipro
19 Replies

4. Shell Programming and Scripting

Split files

Hi , I have 100 records in a.txt file Need to split the a.txt file in to 5 files 1ST File: ex: My file name should be a1.txt - line count in file should be 1 to 15 2ND File: ex: My file name should be a2.txt - line count in file should be 16 to 40 3ND File: ex: My file name... (1 Reply)
Discussion started by: satish1222
1 Replies

5. UNIX for Dummies Questions & Answers

Removing attached doc from an email

How would you approach a problem of removing an attached document from an email? Later I would parse that attachment and put the data into a database. Can do that part. Unfortunately, I'm not use to the various mail programs - have been looking at sendmail and postfix but haven't... (1 Reply)
Discussion started by: TJ_Green
1 Replies

6. Shell Programming and Scripting

Split email message with procmail

Hi, I'm using procmail to ingest incoming messages. The goal is to split the message body into chunks and forward those to a different adddress. Here's a sample of the message body: Group: testgroup --------------------------------------- Host: test1.local:30200 Type: conf Alert:... (9 Replies)
Discussion started by: waltari2001
9 Replies

7. Shell Programming and Scripting

Removing patterns conforming to email addresses

I have a huge collection of text files on my computer. These files contain lots of text in them. The files look like this. Example 1: This is a test file. This is an email address: abc.yahoo.com. This is another line. Example 2: This is another file. The person can be contacted at... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

8. UNIX for Dummies Questions & Answers

to split gz files

Hi, I want to know how to split a gz file ( with out uncompressing it ) Eg:- split -b 10m file.gz (2 Replies)
Discussion started by: daptal
2 Replies

9. UNIX for Dummies Questions & Answers

split files into specified number of output files

Hi everyone, I have some large text files that I need to split into a specific number of files of equal size. As far as I know (and I don't really know that much :)) the split command only lets you specify the number of lines or bytes. The files are all of a different size, so the number of... (4 Replies)
Discussion started by: Migrainegirl
4 Replies

10. Shell Programming and Scripting

removing old files except configuration files and folders

Dear all, I want to remove files older than 2 months in the /home/member directory. But except the configuration files (like .bash_profile .config/ .openoffice/ .local/ .kde/ etc..) I have tried with the command find . -mtime +60 -wholename './.*' -prune -o -print -exec mv {} \; but it... (1 Reply)
Discussion started by: jamcalicut
1 Replies
Login or Register to Ask a Question