help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: To have two delimiter instead of only one


From: Greg Wooledge
Subject: Re: To have two delimiter instead of only one
Date: Wed, 30 Dec 2020 08:13:15 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Dec 30, 2020 at 08:37:43AM +0700, Budi wrote:
> How to have two delimiter instead of only one of char. '/' the ':'
> needs to be honored too, as in this
> 
> while read -d':' -d'/' l;do echo $l ;done < file.txt
> 
> not work, how to solve it ?

First, please tell us what your goals are.  It's not clear what you mean
by "two delimiters", especially when you're using them as the argument
of read -d, rather than IFS separator characters.

Do you mean that you want to terminate the read when you encounter
*either* of the two characters?  Or do you want to terminate the read
when you have seen *both* of them?  If the latter, do they need to
appear consecutively?  Does the order matter?

If at all possible, please show a small example of this mysterious
"file.txt" and tell us how you would like your script to handle the
example you've chosen.

Second, your quotes are wrong.  You don't need single quotes around
the : or / characters (but they don't hurt), but you *do* need double
quotes around the variable expansion "$l".  This is *especially* true
because a file named "file.txt" should be a text file, which means it
should contain one or more newline characters.  Your read -d commands
will not terminate upon seeing a newline, which means newline characters
are going to end up inside the l variable.  You will need proper
quoting to handle them correctly.

It's very likely that whatever you're trying to do, you'll have to find
some other way to do it.  But until we know what it is you want, we
can't help you effectively.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]