Sponsored Content
Top Forums Shell Programming and Scripting HOW TO - Bash REGEX - Print Error when More then One Occurence is Found Consecutively? Post 302716565 by mrm5102 on Tuesday 16th of October 2012 03:19:37 PM
Old 10-16-2012
HOW TO - Bash REGEX - Print Error when More then One Occurence is Found Consecutively?

Hello All,

Bash Version: 4.1.10(1)


I'm trying to "verify" some user input. The User input will contain the "Absolute Path" a "Command" and any "Options"
of that Command.

For Example, say the user's input is:
Code:
user_input="/usr//local/myExample/check_process -p 'java' -w 10 -c 20"

I can't get my REGEX Pattern below to print an error when, say for example the user accidentally inputs 2 "/" consecutively by accident...


My REGEX Pattern/Code is:
*Notice the double "//" after "/usr"...
Code:
user_input="/usr//local/myExample/check_process -p 'java' -w 10 -c 20"

MY_PATTERN="((/{1,1}[[:alnum:]_-]*)+).*$"

if [[ "$user_input" =~ $MY_PATTERN ]]
 then
        echo "TRUE"
else
        echo "FALSE"
fi

So my question is how can I get this to print FALSE when the user enters a double "//"?
I thought the part of my REGEX that has "/{1,1}" would mean match one and ONLY one consecutive "/"...?

Any thoughts would be great..!

Thanks in Advance,
Matt
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print row if value in column 1 is the first occurence

Hi All, I would like to have a script which is able to perform the below. Print the whole row if column1 which is "0001" for the below example is the first occurrence. Subsequent "0001" occurrence will not be printed out and so on. Can any expert help ? Input: 0001 k= 40 0001 k= 2... (7 Replies)
Discussion started by: Raynon
7 Replies

2. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies

3. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

4. UNIX for Dummies Questions & Answers

How to print first occurence

Hi there, how can i print the first pattern occurrence in a .log file? I want to print the filename of the first 17262? I tried but all I can do is print all the lines with the number 17262? I tried using awk and sed but nothing!:wall: I just want filename! Here´s an example: 17259... (3 Replies)
Discussion started by: BMatter
3 Replies

5. Shell Programming and Scripting

sed print between 2 patterns only last occurence

Hi, I have a file, which contains the following log data. I am trying to print fromt he file the following data: I have tried using sed, but I am getting from the first pattern Thanks for your help. (5 Replies)
Discussion started by: sol_nov
5 Replies

6. Shell Programming and Scripting

Print between patterns - first occurence, second occurence etc

I have a file # cat asasas AAAAAA 11 22 33 44 BBBBB NILNILNIL AAAAAA 22 33 44 55 66 77 88 BBBBB NILNILNIL (2 Replies)
Discussion started by: anil510
2 Replies

7. Shell Programming and Scripting

Regex to match only first occurence with grep

Hello to all, How would be the correct regex to match only the first occurence of the pattern 3.*6. I'm trying with 3.*6 trying to match only 34rrte56, but with my current regex is matching 4rrte567890123456789123powiluur56. And if I try with ? doesn't print anything echo... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

8. Shell Programming and Scripting

Help with using awk to print pattern/occurence

Hi, Do anybody know how to use awk to count the pattern at specific column? Input file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a . . Output file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a 3 . . I plan to count how many "miR" in column 3... (2 Replies)
Discussion started by: cpp_beginner
2 Replies

9. Shell Programming and Scripting

Bash - trap error file not found

Hello. In bash, is there a way to trap error "file not found" when a script call another script which is not found; then abort. Example ( part of script running with -x option set) : + return 0 + RETURN_CODE=0 + ] + /root/bin/200_yast_install/00_reset_yast_install bash:... (5 Replies)
Discussion started by: jcdole
5 Replies

10. Shell Programming and Scripting

Print occurence number

Hi folks, I have a file with lots of lines in a text file,i need to print the occurence number after sorting based on the first column as shown below, thanks in advance. sam,dallas,20174 sam,houston,20175 sam,atlanta,20176 jack,raleigh,457865 jack,dc,7845 john,sacramento,4567 ... (4 Replies)
Discussion started by: tech_frk
4 Replies
FAIL2BAN-REGEX(1)						   User Commands						 FAIL2BAN-REGEX(1)

NAME
fail2ban-regex - test Fail2ban "failregex" option SYNOPSIS
fail2ban-regex [OPTIONS] <LOG> <REGEX> [IGNOREREGEX] DESCRIPTION
Fail2Ban v0.8.2 reads log file that contains password failure report and bans the corresponding IP addresses using firewall rules. This tools can test regular expressions for "fail2ban". OPTIONS
-h, --help display this help message -V, --version print the version LOG
string a string representing a log line filename path to a log file (/var/log/auth.log) REGEX
string a string representing a 'failregex' filename path to a filter file (filter.d/sshd.conf) IgnoreRegex: string a string representing an 'ignoreregex' filename path to a filter file (filter.d/sshd.conf) AUTHOR
Written by Cyril Jaquier <cyril.jaquier@fail2ban.org>. Many contributions by Yaroslav O. Halchenko <debian@onerussian.com>. REPORTING BUGS
Report bugs to <cyril.jaquier@fail2ban.org> COPYRIGHT
Copyright (C) 2004-2008 Cyril Jaquier Copyright of modifications held by their respective authors. Licensed under the GNU General Public License v2 (GPL). SEE ALSO
fail2ban-client(1) fail2ban-server(1) fail2ban-regex v0.8.2 March 2008 FAIL2BAN-REGEX(1)
All times are GMT -4. The time now is 02:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy