Need a help in the Shell script which is erroring out

Hi all

I want to add this line after a line

This is the line which needs to be add after the word permission

echo 'profile: /export/home/unix1/auto.pr' >> $xxyy

if [ "$value" = "add" ];then
cd $unixserv/unix
sed '
/permission/ a\
echo 'profile: /export/home/unix1/auto.pr' >> $xxyy
generate_autosys_job.ksh > man5.txt

Can you please let me know what is the error

Its not adding the line as it is :echo 'profile: /export/home/unix1/auto.pr' >> $xxyy

Thanks

try the following:

echo "\047profile: /export/home/unix1/auto.pr\047 >> $xxyy"

the following is not working ..

is there any other way to fix this

Thanks

To output text within single quotes you can place the text within: single quote, double quote, single quote:

echo '"'profile: /export/home/unix1/auto.pr'"' >> $xxyy

Regards

Thanks Guys , But its not working , can you please help m once again ??

This is the code, not able to add the line
echo 'profile: /export/home/'$value'/auto.profile-45' >> $job_name_main'

sed'
/permission/ a\
echo '"'profile: /export/home/'$value'/auto.profile-45'"' >> $job_name_main'

Thanks

any help ?? in this one

Thanks

Hi.

One method is to use double quotes to allow the single quotes to be treated as normal characters. However, because shell variables are expanded within double quotes, the "$" needs to be escaped:

#!/usr/bin/env sh

# @(#) s1       Demonstrate insert of line with single quotes and variable.

set -o nounset
echo

debug=":"
debug="echo"

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash sed

echo

FILE=${1-data1}
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from sed:"

sed "
/permission/ a\
echo 'profile: /export/home/unix1/auto.pr' >> \$xxyy
" $FILE

exit 0

Producing:

% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU sed version 4.1.2

 Input file data1:
This is a line
Another line
This line contains permission.
This is the line that should appear after the inserted line.
Last line.

 Results from sed:
This is a line
Another line
This line contains permission.
echo 'profile: /export/home/unix1/auto.pr' >> $xxyy
This is the line that should appear after the inserted line.
Last line.

Best wishes ... cheers, drl

sed^J/permission:/echo 'profile: /export/home/unix1/auto.pr' >> \$xxyy : not found

This is the error i am getting , any thing wrong in it

Thanks

Can you post you script within code tags?

This is the one which i am using

Have you tried the solution I mentioned earlier?

sed '
/permission/ a\
echo '"'profile: /export/home/unix1/auto.pr'"' >> $xxyy' file

Regards

Yes i tried and it didnot worked

Thanks

Hi.

I tried the solution of Franklin52:

#!/bin/sh -

# @(#) s2       Demonstrate sed insertion with complex quoting.

FILE=${1-data1}

echo
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from sed:"
sed '
/permission/ a\
echo '"'profile: /export/home/unix1/auto.pr'"' >> $xxyy' $FILE

exit 0

producing:

% ./s2

 Input file data1:
This is a line
Another line
This line contains permission.
This is the line that should appear after the inserted line.
Last line.

 Results from sed:
This is a line
Another line
This line contains permission.
echo 'profile: /export/home/unix1/auto.pr' >> $xxyy
This is the line that should appear after the inserted line.
Last line.

So it works correctly for me. That means there are two solutions that appear to work correctly.

Writing:

does not give us enough information.

Post the code you have tried and the results with copy and paste so that we can exactly what you have done, otherwise we're wasting time guessing what the problem might be ... cheers, drl

Hi Thanks for the help ...

I have tried both the codes , it worked , but when i merging this with my script is not working

if [ "$value" = "add" ];then
sed '
/permission/ a\
echo 'profile: /export/home/unix/auto.profile-45' >> job_name_main man7.txt > man8.txt
echo "Profile added "

i am searching for the string permission in man7.txt and once found it should

add this line , can you give me simple code which can merged with if conditions

Thanks Guys !!