Re: sed output and test for nonzero string



Brendan wrote:
Hi there, The following does not work,

Please specify what exactly "does not work" in your case means. Provide
input data and output or error responses.

I assume because sed tacks a
newline on and $t is never a zero length string:

The $( ... ) removes any trailling whitespace characters.

Are you maybe working on a WinDOS file and have some spurious CR at the end?

[code]
t=$(echo $f | sed -n -r '/co[0-9]{1,2}@[a-z]/p')
echo $t
if [ -n $t ]; then
f=$(echo $f | sed 's/@/@_/')
echo $f
fi
[/code]

How do I correctly make this test? Insert an underscore after @ if one
does not already exist, only for strings matching the first pattern?

Provide examples of input data and corresponding output data then it's
easier to show possible solutions. Generally testing with [ -z "$var" ]
or [ -n "$var" ] (or [[ -z $var ]] and [[ -n $var ]] with modern shells
shall work.

Janis
.



Relevant Pages

  • Re: set user=%username%
    ... Your most recent feedback confirms that Windows is ... Type this: echo %MyName% ... > usertest=This is a long string. ...
    (microsoft.public.windows.server.general)
  • Re: its not the school home work
    ... I've learned a bit about strong quotes and think I realized when to ... the shell (such as in the $var, but also for the spaces (that ... echo "foo bar" ... you may say that $string does not appear in /list/ context so ...
    (comp.unix.shell)
  • Re: TRUE and FALSE are treated differently
    ... No -- you can't echo a boolean in PHP. ... If you look up the manual on type casting, you'll find that FALSE is cast ... to an empty string, and TRUE is cast to a non-empty string. ...
    (comp.lang.php)
  • Re: TRUE and FALSE are treated differently
    ... No -- you can't echo a boolean in PHP. ... the boolean is implicitly cast to a string. ... If you look up the manual on type casting, you'll find that FALSE is cast to an empty string, and TRUE is cast to a non-empty string. ...
    (comp.lang.php)
  • Re: WEB SITE PROJECT DEPLOYMENT ~ Help please??
    ... ECHO When/If prompted with the question: ... The files are all now sitting on my Server, and when I load my web site, ... An error has occurred while establishing a connection to the server. ... The connection string specifies a local Sql Server Express instance using ...
    (microsoft.public.dotnet.framework.aspnet)