Linux Shell: how to check a string whether meets some conditions
Hi, guys.
In Linux Shell script, how can I check a string whether meets some conditions.
e.g.:
If a string str must start with a underscore or a alphabet, and it must contains at least one lowercase, one uppercase, one numeric and one punctuation, and its length must be more than 8 characters long and less than 16 characters long, how should I check it?
I can just use the command grep and my command like this:
It just works when determining whether the correct characters included in the string, and it doesn't include the length check. However, it's so wired and so complex and lengthy.
Does anyone have better ideas?
Thanks!
The english language stating the problem is already longer than your source code, I don't know if it can be made truly short. But you're right, grep | grep | grep | grep isn't terribly efficient. You could do it in several case statements and use ${#string} to get its length, or pile it all into an awk statement, which isn't terribly efficient itself, but better than five greps, and easier to see what you're doing.
The english language stating the problem is already longer than your source code, I don't know if it can be made truly short. But you're right, grep | grep | grep | grep isn't terribly efficient. You could do it in several case statements and use ${#string} to get its length, or pile it all into an awk statement, which isn't terribly efficient itself, but better than five greps, and easier to see what you're doing.
Hello.
I need to find all files but excluding some because
I need to exclude some sub-folders
I need to exclude some filenames
Files must be within two dates.
The result is sent to a function
I cannot achieved to put together the date conditions, the folder conditions and the... (4 Replies)
So, there is a large file where I have to conduct several search using bash shell scripting.
The file is like this:
TITLE and AUTHOR ETEXT NO. Aspects of plant life; with special reference to the British flora, 56900 by Robert Lloyd... (1 Reply)
I wish to check two conditions inside the if statement
Condition 1: The two file contents should be identical // using cmp command for this.
Condition 2: The two filenames should NOT be the same.
This is what i did in vain.
if ]; then
where entry1 and entry2 are
ls *.txt | while... (7 Replies)
Hi Everyone,
Just in need of your help again, I have managed to get a script to check the linux disk usage stuff. But wanted to tweak it little more to get the desired output.
Requirement:
Now its querying only one mount point, As its not saving in array instead calling it as variables. So... (1 Reply)
All,
Here is what I am trying to accomplish:
1. Check for a file of specific name recursively and when I find it,
a. if the file is more than 1hr old, no need to email or send notification, so just exit out from the shell script
b. if the file is less than 1hr old, send an email to me saying... (3 Replies)
hello,
i have a variable which should have following content :
var="value1"
or
var="value2"
or
var="value2:*" # example: value2:22
how can i check :
- if the content is ok (value1 / value2* )
- the two options of "value2"
when content is example "value2:22" , i want to split... (3 Replies)
This is what I have so far
grep -lir "some text" *
I need to check all files on the system for this text, if the text is found I need to change the file permissions so only ROOT has read and write access.
How can this be done? (3 Replies)
Hi,
Can anyone help me out to check whether the input argument is number?
Example:
REQUEST_ID="123456"
I need to check the REQUEST_ID value is number or string.
Thanks in Advance
Regards
BS (6 Replies)