1753813 Members
7914 Online
108805 Solutions
New Discussion

problem with sed command

 
praveen..
Super Advisor

problem with sed command

I am facing the problem with the sed on my server.

My requirement is to change the filename in the ssort and awk scripts to point to the correct directory. To change the directory I need to delimit the “/” so as to have it “\/” in the variable to be successful with the sed.

The limitation with the ssort is it will not accept the second occurrence of the /INFILE as a variable (like /INFILE $1)

So we have to use the sed to replace the FILE_NAME after the /INFILE to point to the correct directory.

At the time of testing the sed is giving the problem.

It is successful with the command (2), but with the tilda(`) to assign it to variable it is giving the below error, command (3).

1) $ FINAL_MANUF=/apps/aloyan/loading/data;export FINAL_MANUF

2) $ echo $FINAL_MANUF|sed 's/\//\\\//g'

\/apps\/aloyan\/loading\/data

3) $ UPC_REJECT=`echo /OPT/LOYAN/LOADING/DATA_TEMP/UPC_REJECT|sed 's/\//\\\//g'`

sed: Function s/\//\\//g cannot be parsed.



is it a problem with the sed?
i tried with "sed" command with its full path "/usr/bin/sed", still I am getting the same error:
sed: Function s/\//\\//g cannot be parsed.

please suggest

 

 P.S.This thread has been moved from HP-UX>System Administration to HP-UX >  langages- HP Forums Moderator

11 REPLIES 11
RAC_1
Honored Contributor

Re: problem with sed command

How about plain tr?

echo "/apps/aloyan/loading/data" | tr '\/' '\\' gives

\apps\aloyan\loading\data
There is no substitute to HARDWORK
Arunvijai_4
Honored Contributor

Re: problem with sed command

Hello,

Why not this,

#echo "/apps/aloyan/loading/data" |sed 's/\/\\//g'
/apps/aloyan/loading/data


-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Jannik
Honored Contributor

Re: problem with sed command

$ FINAL_MANUF=/apps/aloyan/loading/data;export FINAL_MANUF
$ echo $FINAL_MANUF|sed 's/\//\\/g'
\apps\aloyan\loading\data

$ UPC_REJECT=`echo /OPT/LOYAN/LOADING/DATA_TEMP/UPC_REJECT|sed 's/\//\\\/g'`
$ echo $UPC_REJECT
\OPT\LOYAN\LOADING\DATA_TEMP\UPC_REJECT

jaton
praveen..
Super Advisor

Re: problem with sed command

is this scripts related problem or "sed" command related problem?

how to resolve this?
Arunvijai_4
Honored Contributor

Re: problem with sed command

Hi,

This is a script problem with usage of sed. Not a problem with "sed".

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Peter Nikitka
Honored Contributor

Re: problem with sed command

Hi,

your escapes via \ mus be doubled, if processing of the string is doubled:
in a plain echo '\\', in an execution in `` you have to use '\\\\'. As a side effect, echo may recognize character special sequences ('\n') you not intend to be performed.

You can do this assignment nearly without esacaping:

echo /OPT/LOYAN/LOADING/DATA_TEMP/UPC_REJECT|sed 's:/:\\:g' | read UPC_REJECT

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
praveen..
Super Advisor

Re: problem with sed command

Hi,
I am able to get the correct output when i use the command on $ sign.

but when i create a script with the same command, it is giving the error.
sed: Function s/\//\\//g cannot be parsed.


i have changed this file permission to 777

please suggest what to do.
Peter Nikitka
Honored Contributor

Re: problem with sed command

Hi,

using my approach in a script (ksh, posix-shell) worked for me - which shell do you use in your script?

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
praveen..
Super Advisor

Re: problem with sed command

I am using "ksh" shell