You are welcome. If you try:
You'll notice that the first one evaluates to -n and the second one to -n ''
In the first case the there is no protection of variable p, which contains an empty field. Since there is not protective quotes around $p, the result is field split and since $p is empty this results in 0 fields. So wat remains "-n" which is a test if the string "-n" is non empty
([ "$somestring" ] if the same as [ -n "$somestring"], I prefer the latter for clarity, so in fact [ -n ] is equivalent to [ -n -n ])
In the second case the result of "$p" is not field split and so the -n is interpreted as an operator with one field as parameter, which contains an empty variable, and this evaluates to false .
So that is yet another reason to put quotes around variable expansions.
I hope this clarifies things...
Last edited by Scrutinizer; 06-21-2016 at 03:55 PM..
This User Gave Thanks to Scrutinizer For This Post:
Hi,
I need to delete an empty directory in a temp directory except "dir5" (keep everything that is not empty).
Plese advise.
Here is an example of my directory.
/dir/temp/
dir1 - delete if this is empty
dir2 - delete if this is empty
dir3 - delete if this is empty
dir4 - delete if this... (7 Replies)
I know this one was answered before in forum below -
https://www.unix.com/unix-dummies-questions-answers/58210-removing-empty-folders-using-find-command.html
But that one is closed & I have a question so here it goes.
I want to delete all 2006 files. Now if along with the files, if the... (2 Replies)
Hello:
I searched here for "vi -c" but found no hits.
How can I use vi -c to remove ALL empty lines, regardless of how many?
I tried
<code>
vi -c ":g/^$/d | wq" filename
</code>
but I have to run it several times.
This is NOT homework. :)
Thanks for your time. (3 Replies)
Hi all,
I'm trying to remove when this condition is met: an empty and the next one
I'm using this command:
sed '/^$/N; s/&//' file
Which searches for an empty line, N attaches it to the next line, and substituing the combination with nothing.... but it is not working.
What I'm missing... (1 Reply)
Hi all !
I'm sure it is a basic question but I didn't find any threads that fit my need.
How to remove empty fields with awk?
Or in other words, how to shift all the fields after an empty field on the left?
input:
1|2||3|4|5||6
wanted:
1|2|3|4|5|6
I tried:
awk '{for(i=1; i<=NF;... (7 Replies)
Hello:
Is there a simple way to remove empty records of FASTA format file?
A FASTA format consists of two parts: header and sequence (for non-biologist, Wiki for details of course!). The header always start with ">" for the name of the sequence. The header must be in this ONLY single line.... (9 Replies)
Hello,
I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be:
SRVXPAPI001 ERRO JUN24 07:28:34 1775
REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F
... (8 Replies)
Hi all,
I've got a file that has 12 fields. I've merged 2 files and there will be some duplicates in the following:
FILE:
1. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, 100
2. ABC, 12345, TEST1, BILLING, GV, 20/10/2012, C, 8, 100, AA, TT, (EMPTY)
3. CDC, 54321, TEST3,... (4 Replies)
Discussion started by: tugar
4 Replies
LEARN ABOUT OPENDARWIN
expr
EXPR(1) BSD General Commands Manual EXPR(1)NAME
expr -- evaluate expression
SYNOPSIS
expr expression
DESCRIPTION
The expr utility evaluates expression and writes the result on standard output.
All operators are separate arguments to the expr utility. Characters special to the command interpreter must be escaped.
Operators are listed below in order of increasing precedence. Operators with equal precedence are grouped within { } symbols.
expr1 | expr2
Returns the evaluation of expr1 if it is neither an empty string nor zero; otherwise, returns the evaluation of expr2.
expr1 & expr2
Returns the evaluation of expr1 if neither expression evaluates to an empty string or zero; otherwise, returns zero.
expr1 {=, >, >=, <, <=, !=} expr2
Returns the results of integer comparison if both arguments are integers; otherwise, returns the results of string comparison using
the locale-specific collation sequence. The result of each comparison is 1 if the specified relation is true, or 0 if the relation
is false.
expr1 {+, -} expr2
Returns the results of addition or subtraction of integer-valued arguments.
expr1 {*, /, %} expr2
Returns the results of multiplication, integer division, or remainder of integer-valued arguments.
expr1 : expr2
The ``:'' operator matches expr1 against expr2, which must be a regular expression. The regular expression is anchored to the begin-
ning of the string with an implicit ``^''. expr expects "basic" regular expressions, see re_format(7) for more information on regu-
lar expressions.
If the match succeeds and the pattern contains at least one regular expression subexpression ``(...)'', the string corresponding to
``1'' is returned; otherwise the matching operator returns the number of characters matched. If the match fails and the pattern
contains a regular expression subexpression the null string is returned; otherwise 0.
Parentheses are used for grouping in the usual manner.
EXAMPLES
1. The following example adds one to the variable a.
a=`expr $a + 1`
2. The following example returns the filename portion of a pathname stored in variable a. The // characters act to eliminate ambiguity
with the division operator.
expr //$a : '.*/(.*)'
3. The following example returns the number of characters in variable a.
expr $a : '.*'
DIAGNOSTICS
The expr utility exits with one of the following values:
0 the expression is neither an empty string nor 0.
1 the expression is an empty string or 0.
2 the expression is invalid.
STANDARDS
The expr utility conforms to IEEE Std 1003.2 (``POSIX.2'').
BSD July 3, 1993 BSD