Operating System - HP-UX
1831477 Members
3417 Online
110025 Solutions
New Discussion

Strange Issue With sed command

 
Amit Dixit_2
Regular Advisor

Strange Issue With sed command

Hi,
We are having a script which gets executed whenever we recieve a file in a particular mailbox and the script is suppose to move the file to another folder and before that It does following processing using sed

sed -e "1,25s/^charset=/ charset=/g" /tmp/${FILENAME} >
/tmp/${FILENAME}.tmp

What I understand from the above command is it is replacing the TAB space from the mail header.

But What is happening is when it processes mail using sed and moves to the folder Intergration Server processes the first document but fails with other files and what we noticed in the header is the success one's and failed once are having different headers.

Can anyone please help.

Thanks,
Amit.
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: Strange Issue With sed command

Hi Amit:

As written this code processes the first 25-lines (1-25) of /tmp${FILENAME}. If, anchored (^) to the beginning of a line, string "charset=" appears, a space (blank) character is inserted before the string. The output is, including any lines beyond #25 that do not receive substitution is written to /tmp/${FILENAME}.tmp.

There is no TAB character apparent in your post.

Regards!

...JRF...
Sandman!
Honored Contributor

Re: Strange Issue With sed command

Amit,

JRF is correct, no TAB character in the substitution pattern. Could you clarify the following lines:

>> But What is happening is when it processes mail using sed and moves to the folder Intergration Server processes the first document but fails with other files and what we noticed in the header is the success one's and failed once are having different headers <<
Hein van den Heuvel
Honored Contributor

Re: Strange Issue With sed command

The forum software mangles spaces and tab, converting any combination of then to a single space.
So if you need to show a tab in this forum, then you'll need to use a numeric representation like the octal 011 or dec 9 for HT, or a control char or the 'od' output with the text. Better still attach a text file with the exact charaters (do NOT cut & paste from screen as again this will mangle tabs)


The sed "1" command can show control characters in the pattern space.
Depending on the shell and such you can enter a true tab only by typing control-v followed by control-i sometimes shown as ^t.
Some versions of sed support \t for TAB or just use that \011


Still... like JRF writes, the command line suggests you are trying to add a space or tab, not replace is. Please clarify. Do you want a tab/spaces added to the output, or removed from the input. In the latter case you'd have to swap the substitue components around (from /x/y/ to /y/x/ )

fwiw,
Hein.
Jean-Yves Picard
Trusted Contributor

Re: Strange Issue With sed command

Hello,

apart from tab problem, you say
>> Server processes the first document but fails with other files

what is value of ${FILENAME} ?

if you have 3 files
maila mailb mailc
and FILENAME="maila mailb mailc"

the result of
sed -XXX ${FILENAME} > ${FILENAME}.tmp
is
sed -XXX maila mailb mailc > maila mailb mailc.tmp

which might not be what you want.
what you want is more likely
FILENAME=$(any command that list files except .tmp files)
for f in ${FILENAME}
do
sed -XXX $f > $f.tmp
done


Jean-Yves
Vipin Singhal
Super Advisor

Re: Strange Issue With sed command

Hey Amit,
Are you from BSACET????

Thanks
Vipin
Frank de Vries
Respected Contributor

Re: Strange Issue With sed command

Hey Vipin
shouldn't that be
ASBECT ?
Look before you leap