Sponsored Content
Top Forums Shell Programming and Scripting Trigger email from script if the Special Character replacement is successfull Post 302944429 by derekludwig on Tuesday 19th of May 2015 08:33:55 AM
Old 05-19-2015
Nanduedi,

Are asking for an email if a "special character" was found in ECEPYO.dat?

I would also separate the function of checking for "special characters" from the function of removing them, with
Code:
#!/bin/bash

SDIR=/mnt/G/Inbound/Pre-Prod/GEM/From_O/Scriptprocess 
FILE=ECEPYO.dat
ADDR=xyz@gmail.com

cd $SDIR || exit 1
test -f ${FILE} || exit 2
test -s ${FILE} || exit 0

TEMP=$(mktemp)
LIST=$(mktemp)
trap "rm -f ${TEMP} ${LIST}" EXIT

for special in ’ \\ é à — –  \`; do
  grep -n "${special}" ${FILE} > ${LIST}
  
  if [[ -s ${LIST} ]]; then
    echo
    echo "${special}": $(cut -d: -f1 ${LIST})
  fi >> ${TEMP}
done

if [[ -s ${TEMP} ]]; then
  mailx -s "SpecialCharacters were found" ${ADDR} < ${TEMP}
fi

(! untested !)

` and \ are "special characters"?

I do have to admit to some trepidations. The directory the script changes into is a subdirectory of /mnt? This is typically used for temporary mounts.

Why the while loop? Your script only processes a single file: ECEPYO.dat.

Simplifying your original script:
Code:
#! /bin/bash

FDIR=/mnt/G/Inbound/Pre-Prod/GEM/From_O
SDIR=$FDIR/Scriptprocess 
FILE=ECEPYO.dat

cd $SDIR || exit 1
test -f ${FILE} || exit 0

sed -e 's/’/ /g' \
    -e 's/\\/ /g' \
    -e 's/é/ /g' \
    -e 's/Ã//g' \
    -e 's/—/ /g' \
    -e 's/–/-/g' \
    -e 's/Â//g' \
    -e 's/`/ /g' $FILE >> $FDIR/$FILE


Last edited by derekludwig; 05-19-2015 at 09:34 AM.. Reason: typo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Special Character Check in Shell script

Hi, I'm currently working on a project that requires parsing xml file. One of the field in the xml is shown below (don't remember exactly): <variable="ITEM">12345678</variable> I coded my script keeping in mind that the value denoted in bold will always be a number. After getting just the... (1 Reply)
Discussion started by: mradul_kaushik
1 Replies

2. Shell Programming and Scripting

Character replacement

Hi, I am working on a command that replaces some occurrences of quotation marks in file. The quotation mark cannot be the first or the last character in line and cannot be preceded or followed by a comma. I am not an expert in regular expressions, but I managed to create the following... (2 Replies)
Discussion started by: piooooter
2 Replies

3. Shell Programming and Scripting

Sed-Special character replacement

Hi I want to replace ./testsed.ksh with testsed.ksh ./ is to be removed scriptnm=`sed -e 's/\.///' $0 does not work Please help (3 Replies)
Discussion started by: usshell
3 Replies

4. Shell Programming and Scripting

Script not successfull in cron

Hi, I have a script to FTP the files to other unit. Manually this script is running fine & files are getting transferred. But running the same script using crontab does not transfer files, although the cron log shows that the file was executed. PLz suggest (2 Replies)
Discussion started by: sandeep_kmehra
2 Replies

5. Shell Programming and Scripting

Perl Script Syntax to Extract Everything After Special Character

Hi, I am writing a Perl script that reads in many lines, if a line meets the criteria I want to edit, it. For example, the script will return the following example line... test=abc123 All I want to do is strip off the "test=" and just be left with the abc123. In my script I can easily... (3 Replies)
Discussion started by: edrichard
3 Replies

6. UNIX for Dummies Questions & Answers

banner character replacement

Can we able to replace the character # in banner command with some other characters. Can we able to blink the character in Kornshell (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

7. Shell Programming and Scripting

Use arrow touch in a script shell without special character

Hello, I have a problem when i execute the script underneath. If i tape azerty 123 and i use the arrow touch, in the file /tmp/test i have the caracter #!/usr/bin/ksh clear echo "Taper l adresse IP de la partition a creer :" tput cup 1 48 read Adress echo $Adress echo "${Adress}" >>... (0 Replies)
Discussion started by: khalidou13
0 Replies

8. Shell Programming and Scripting

calling another script if it's contains SUCCESSFULL how?

Hi all, i'm a newbie here, I'm just wondering how can i call my second script if it's contain successfull. script1.sh how can i call my 2nd script if he contain SUCCESSFULL script2.sh SUCCESSFULL please advise, Thanks, (10 Replies)
Discussion started by: nikki1200
10 Replies

9. Shell Programming and Scripting

Shell script question in special character

when I execute the unix commands its works normally in the 1st part. When I the tried the same in shell scripting the directory is not displayed in 2nd part example. please let me know what needs to be done. Unix : client=~zsvdbs echo $client /shome/zsvhome/zsvdbs Using... (3 Replies)
Discussion started by: keerthi2016
3 Replies

10. Shell Programming and Scripting

Special character replacement

Hi Guys, I have a file which needs to be replaced with tab delimited AA§Orgin Name§Mapping based on prod_usa§§§§ BB§Date§2019-08-11 23:30:01§§§§ I am trying below code sed 's// /g' test.txt Expected AA|Orgin Name|Mapping based on prod_usa||| BB|Date|2019-08-11 23:30:01|||| (6 Replies)
Discussion started by: rohit_shinez
6 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a filename containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 10:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy