(imported topic written by Trailsuender)
How to count the number of lines of a file which do NOT start with a “#” ?
I really would appreciate any help!
(imported topic written by Trailsuender)
How to count the number of lines of a file which do NOT start with a “#” ?
I really would appreciate any help!
(imported comment written by jgstew)
Look at the property "
" in the analysis “
hosts file
” here:
http://bigfix.me/analysis/details/2994561
number
of
lines
whose
(
it
does
not
start
with
“#”
AND
it
as
trimmed string does
not
equal
""
)
of
file
"hosts"
of
(
if
windows
of
operating system
then
folder
"drivers\etc"
of
system x64 folder
else
if
mac
of
operating system
then
folder
"/private/etc"
else
folder
"/etc"
)
(imported comment written by Trailsuender)
What do I make wrong or not understand?
This is ok:
Q: number of lines whose ( it does not start with "#" and it as trimmed string does not equal "" ) of file "/etc/sudoers"
A: 15
T: 239
This is also OK
Q: exists file "/etc/sudoers"
A: True
T: 53
Q: if exists file "/etc/sudoers" then "file exists" else "file missing"
A: file exists
T: 54
But this delivers “Incompatible types”???
Q: if exists file "/etc/sudoers" then number of lines whose ( it does not start with "#" and it as trimmed string does not equal "" ) of file "/etc/sudoers" else "file missing"
E: Incompatible types.
What the heck! Why incompatible types???
I assume I will never find any logic structure or structure at all in reference language such as in Pascal or C… :-/
I am completely confused…
(imported comment written by RitchieD)
Both the results of the if/then/else statement have to return the same type. You have a numeric and a string.
e.g:
Q: if True then 1 else “test”
E: Incompatible types.
Q: if True then 1 as string else “test”
A: 1
T: 0.041 ms
I: singular string
(imported comment written by Trailsuender)
OK, this works:
if exists file “/etc/sudoers” then number of lines whose ( it does not start with “#” and it as trimmed string does not equal “” ) of file “/etc/sudoers” as string else “/etc/sudoers missing”
It is necessary to apply “as string” to the “number of lines…” statement.
Cheers, Roland
(imported comment written by jgstew)
There is another option, a custom error message.
if exists file “/etc/sudoers” then (number of lines whose ( it does not start with “#” and it as trimmed string does not equal “” ) of file “/etc/sudoers”) else ERROR “/etc/sudoers missing”
(imported comment written by jgstew)
The reason it is saying incompatible types is both results of an If/Else statement must return the same type. If one returns a string, so must the other. You are returning a number and a string depending on which branch of the IF/Else statement is taken, which is not allowed. You either must convert them to the same type, which is what you did below, or you must use a custom ERROR message which does not need to follow this type compatibility due to the nature of it.
(imported comment written by Trailsuender)
OK, thanks for the hint. So, if then else’s" is treated like a function, which only has normally a defined return type instead of a procedure (just generating output and if needed value by reference). This makes in some way sense within relevance language.
Still missing full relevence language documentation from IBM to look up key words such as “trimmed string”…