[lug] Help for Parsing Shell script
stimits at idcomm.com
Tue Feb 27 21:30:13 MST 2001
> Marco Garutti wrote:
> I'm Marco Garutti, writing from Tecnoform S.p.A. (Italy)
> I need to create a shell script that parse an .htm file and add it
> lines, via echo
> The problem is that echo doesn't reproduce my input as it is.
> For example, a string that i read like:
> ^[^LNS / NR.ID:
> after echo becomes:
> ^[^LNS / NR.ID: IT00513691204
> that is wrong, for what I'm looking.
> And again, how to grep a substring parsing lines; when I find out it I
> have to add on other lines.
> I'm not so expert using Unix script language so I'm asking for help.
> Thanks in advice.
> Marco Garutti
What is your current script? You might be interested in knowing that the
control-M (^M, or carriage return, '\r' in C) is normally discarded from
an echo. Some other special characters are also discarded from an echo
if not escaped. The "-e" option for "echo -e whatever" makes sure escape
notation will work if used. Once this is set, you need to escape those
control characters. A demonstration with the backspace character helps.
The escape notation for backspace is \b, try these to see the difference
of escaping turned off or on, from a bash prompt (turn off end of line,
and put your own in, which is \n):
echo -E -n "abc\bdef\n"
echo -e -n "abc\bdef\n"
The "-E" turns off escape abilities, "-e" turns on escape abilities. The
"-n" turns off automatic newline at end of echo, in which case you need
to add your own.
D. Stimits, stimits at idcomm.com
More information about the LUG