Operating System - HP-UX
1837439 Members
3455 Online
110116 Solutions
New Discussion

how to investigate a file line fore line

 
SOLVED
Go to solution
Mark Rossen
Occasional Contributor

how to investigate a file line fore line

Hello

I have a file with emailadresses and descriptions both fixed length. how can i investigate the file line for line to mail de description to the emailadres at the beginning of the line.

sample file:
email@adres1 this is description for adres 1
email@adres2 this is description for adres 2
etc

10 REPLIES 10
Vincenzo Restuccia
Honored Contributor

Re: how to investigate a file line fore line

cat file|grep email@adres1
Vincenzo Restuccia
Honored Contributor

Re: how to investigate a file line fore line

In vi search with "/" email@adres1 and "n" for next search.
Mark Rossen
Occasional Contributor

Re: how to investigate a file line fore line

I forgot to say that i have to use a script because i want to email every day, maybe every hour. In yhe production file i don't know what the emailadresses are. I only know that the email adressen are on position 1 to n of each line
James R. Ferguson
Acclaimed Contributor
Solution

Re: how to investigate a file line fore line

Hi Mark:

# while read ADDR DESC
> do
> mailx -s "$DESC" $ADDR < /dev/null
> done < myfile

This will mail each ADDR a message whose subject is the DESC (one or more words!). The body of the message will be empty (/dev/null) although you could specify any file appropriate.

Regards!

...JRF...
Stefan Schulz
Honored Contributor

Re: how to investigate a file line fore line

Hi Mark,

i don't have the time to write a whole script right now. But i would use the following parts.

sed -n -e "$n P" filename

This will get line numer $n from the file filename. Put this in a variable or something. Then i would use cut to get the email adress and the rest seperated.

echo $line | cut -f1 -d' '

this will get you the first field of the line, where a blank is the field seperator. This should be your emailadress.

echo $line | cut -f2- -d' '

the rest of the line (filed 2 to the end). Now you can use this information to feed your desired mailapplication like elm, mail, pine ....

Put the whole thing in a loop to read the file line by line.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Vincenzo Restuccia
Honored Contributor

Re: how to investigate a file line fore line

Identify a separator and try awk with option -F.
federico_3
Honored Contributor

Re: how to investigate a file line fore line

cat file | awk '{print substr($0,1,n)}'

with the command upon you'll get the addresses.


Federico
Herve BRANGIER
Respected Contributor

Re: how to investigate a file line fore line

Hi,

try :

cat | awk '{b=index($0," "); if (length($0) > 0) system ( "echo \" " substr($0,b) "\" | mail " substr($0,0,b) )}'


This will generate system calls like :

echo "DESCRIPTION TEXT" | mail "EMAIL ADDRESS"
for each non empty lines

HTH

Herv?

Rainer von Bongartz
Honored Contributor

Re: how to investigate a file line fore line


while read line
do
dest=`echo $ line | cut -f1 -d' '`
subj=`echo$ line | cut -f2- -d' ' `
mailx -s $subj $dest
done < yourfile

should do the job
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Stefan Schulz
Honored Contributor

Re: how to investigate a file line fore line

Hahaha,

as so often JRF postet first with the best solution.

James, i already learned a lot. Hope you stay with us for a long time. There is still plenty i have to learn.

BTW: when do you plan to reach the 20000 points ;-)

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.