Sponsored Content
Top Forums Shell Programming and Scripting sed or awk removes attachment in email Post 303038516 by Harish7586 on Thursday 5th of September 2019 04:53:24 AM
Old 09-05-2019
Sed or awk removes attahcment in code

Code:
#!/usr/bin/ksh

parse_file()
{
["$*" = ""] && return
[ ! -f "$1"] && return
eval echo "\"$(cat $1 | sed '87s/Member/Harish R/g')\""
}

export MAILTO="abc@xyz.com"
export SUBJECT="Test PDF for Email"
export BODY="/export/user/abc.html"
export NEW_BODY="/export/user/temp_content.html"
export ATTACH="/export/use/file1.pdf"
export MAILPART='uuidgen' ## Generates Unique ID
export MAILPART_BODY='uuidgen' ## Generates Unique ID
export AWK=/usr/xpg4/bin/awk
#echo "sed -i '87s/Member/Harish R/g' "$BODY" > "$NEW_BODY""
cp $BODY $NEW_BODY
#cat "$NEW_BODY" |/usr/bin/awk -v awkfrom="Member" -v awkto="Harish R" '{gsub(awkfrom,awkto)}' > $NEW_BODY
#$(echo cat $NEW_BODY | $AWK -v awkfrom="Member" -v awkto="Harish R" '{gsub(awkfrom,awkto)}')
#sed -i '87s/Member/Harish R/g' "$BODY" > "$NEW_BODY"
(
 echo "From: $MAILFROM"
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
 echo ""
 echo "--$MAILPART"
 echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
 echo ""
 echo "--$MAILPART_BODY"
 echo "Content-Type: text/plain; charset=ISO-8859-1"
 echo "You need to enable HTML option for email"
 echo "--$MAILPART_BODY"
 echo "Content-Type: text/html; charset=ISO-8859-1"
 echo "Content-Disposition: inline"
 $(parse_file $NEW_BODY)
#cat $NEW_BODY
 echo "--$MAILPART_BODY--"
 
 echo "--$MAILPART"
 echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: uuencode"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 echo ""
 #uuencode -m $ATTACH $(basename $ATTACH)
 uuencode $ATTACH $(basename $ATTACH)
 echo "--$MAILPART--"
 
)| /usr/sbin/sendmail $MAILTO

Please find my code above. I tried editing the body html file. At the moment it works if we just give cat $NEW_BODY however when i edit the file using sed or awk then it fails to send attachment but content is as expected
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Email Attachment

Hi, I have 2 questions regarding sending mail as attachment. 1. Using mime type (From Oracle tools which reside on UNIX) When send the mail(txt file) as an attachment, on some servers like Hotmail, the email goes perfect as an attachment. But on some servers like yahoo, get embedded mail which... (2 Replies)
Discussion started by: prasad01
2 Replies

2. UNIX for Dummies Questions & Answers

Email Attachment

Is there a way to send an email attachment? So far no where I've looked has given me any leads. (2 Replies)
Discussion started by: Cyro
2 Replies

3. AIX

Email with Attachment

Hi, I have .ksh file which internally calls a .sql file. This sql file writes a file with the result. I am using the following command to send email with the result file as attachment uuencode file.txt file.txt | mail -s "Subject" abc@abc.com. When i run the .ksh file i get a message you... (5 Replies)
Discussion started by: piyushprabhakar
5 Replies

4. Shell Programming and Scripting

sed command removes lines in file

Hi, I am modifying a file with sed command. i want to make SCORE= blank in the file whereever SCORE=somevalue. What will *$ do in the below command? cat $file | sed 's/SCORE=.*$/SCORE=\r/g' > newfile The last line is also missing in the new file. How to make SCORE='100' to SCORE=... (5 Replies)
Discussion started by: ashok.k
5 Replies

5. UNIX for Advanced & Expert Users

perl/sed -i removes link

hello, is it a behavior of or that "-i" removes unix link . example : i create a file "src_file" and link it to "link_file" and then i start "perl -i" the link is removed. does another option exists to change content of a file without temporary files ? UNIX-Version: HP-UX and... (2 Replies)
Discussion started by: bora99
2 Replies

6. Solaris

Sent an email attachment, but the attachment is empty

I'm trying to send a .zip file from my unix box to my work email (email client outlook) The file name that I'm trying to sent is sites.zip and this is how I do it: uuencode sites.zip | mailx -s "testing" myname@mydomain.com When I open the .zip, the zip is empty. Looking around the we, I... (17 Replies)
Discussion started by: amb1s1
17 Replies

7. Shell Programming and Scripting

Sed: removes \ from text which causes issues

Hi all, Hoping someone hoping someone might be able to help. i've got the following sed command which i'm using in a bash script that i'm trying to use to insert a new line into an already existing file so i don't have to manually enter it when setting stuff up. the existing script test2/3 are... (3 Replies)
Discussion started by: springs2
3 Replies

8. UNIX for Dummies Questions & Answers

Why awk removes delimiters?

Code : echo "1,2,3,4"|awk -F "," 'NR==n{$3=a}1' n=1 a=45 Output : 1 2 45 4 Expected : 1,2,45,4 (4 Replies)
Discussion started by: Rajesh_us
4 Replies

9. Shell Programming and Scripting

Attachment in email

I have a file in unix, while i do email that file to some one from unix, the attachment file data is displaying in the email. (as body of the email). but if the file has some special characters , the file is emailing as attachment. But i need the file as the body in the email if it has special... (1 Reply)
Discussion started by: nani1984
1 Replies

10. Shell Programming and Scripting

awk removes delimiter unexpectedly

datafile: blah,blah,blah,blah,blah,blah,blah,blah,blah=0_nblah=0-- ,blah,blah,blah im using the following command to turn the "_n" and "-- " to just a space " " only in the $9th field. meaning, it has to make the changes only in the 9th column/field of the datafile. awk -F, '{... (1 Reply)
Discussion started by: SkySmart
1 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.10 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 04:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy