I have a number of files that I need to return a yes for this command.
However, the files look like this:
Apparently the files are not picked up because of spaces. Can someone help? The first word only is picked up. It appears that if I do this:
echo $file returns the correct string but I don't know how to make the regex see the string correctly. How would I be able to send a list of files with the space pattern to a variable?
Wouldn't it be helpful if you posted your OS and shell versions? Above smells like bash, but this assumption can be wrong.
How is your file variable defined? In a for loop (which would explain the cited behaviour)? With a read?
BTW, you don't have problems with a "regex with spaces", but with spaces in variables / data that are incorrectly interpreted.
Apparently the files are not picked up because of spaces.
I do not think so. One of the differences between [ and [[ is that [[ is a shell-built-in replacement for test and field splitting is not done inside it. To see the difference try
You will notice that one produces a syntax error because of the unquoted blank and the other works fine - because field splitting at blanks is not done.
But there is another problem:
The quotes will make sure the regexp never matches, because they are retained. Try:
And also the && is not the correct AND-operator for test, it is used only in the shell! So either you couple two test-statements via a shell-AND:
or you do it inside test with the test-internal operator:
I do not think so. One of the differences between [ and [[ is that [[ is a shell-built-in replacement for test and field splitting is not done inside it. [..]
To put a fine point on it: Every modern shell has [/test as a shell builtin (utility) and since it is still a utility, variables are expanded and field splitted so that they can be passed as fields to the utility.
[[ on the other hand, is a conditional expression which is part of the shell syntax and therefore no field splitting is performed (similar to what happens to variables in a case statement, which is also shell syntax)
---
On another note: RudiC was not referring to field splitting in the conditional expression, but the possibility that the variable does not contain the full filename and that that may be due to the way the filename was passed to the variable:
Quote:
Originally Posted by RudiC
How is your file variable defined? In a for loop (which would explain the cited behaviour)? With a read?
Last edited by Scrutinizer; 03-31-2018 at 07:05 AM..
This User Gave Thanks to Scrutinizer For This Post:
Actually, the test looks if there's just any single upper case char OR any whitespace in the variable's contents; so both examples should print yes, as does a a string or a 1234S2345. You may want to reconsider your problem.
I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works:
LOCAL_CONFIG
#
Kcheckaddress regex -a@MATCH
+<@+?\.++?\.(us|info|to|br|bid|cn|ru)
LOCAL_RULESETS
SLocal_check_mail
# check address against various regex... (0 Replies)
I am not a big expert in regex and have just little understanding of that language.
Could you help me to understand the regular Perl expression:
^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{
------
This is regex to select functions from a C/C++ source and defined in... (2 Replies)
I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header.
In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Hey all,
I have a very simple regular expression that I use when I want to allow only letters with spaces. (I know this regex has a lot of shortcomings, but I'm still trying to learn them)
isAlpha='^*$'However, when I bring this over to BASH it doesn't allow me to enter spaces.
I use the... (3 Replies)
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Hello All,
I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out.
My file is like this (<b> means one blank space, <t> means one tab space)-
$ cat file
NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
How do I write a regular expression to capture the comments of Pascal which are usually delimted by (* and *) or { and }? And also I need a regular expression to express financial quantities in American Notation. They have a leading dollar sign and an optional string of asteriks,a string of decimal... (1 Reply)
Hi,
I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is.
I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Hi,
I am trying to grep for the following type of string from a document given below:
12637 1239 3356 12956 7004 7004 7004 13381 13381
*> 12.0.1.63 0 7018 21872 ?
* 208.51.134.254 53 0 3549 7018 21872 ?... (1 Reply)
I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help.
echo $SH_VAR | command_line Syntax.
The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)