Sponsored Content
Top Forums Shell Programming and Scripting Regex to validate parameter for sleep Post 303025544 by RudiC on Monday 5th of November 2018 09:42:47 AM
Old 11-05-2018
OK, multiple dots, and any non-numeric characters discriminated as well:


Code:
sed -r '/[^0-9+.]/bW; /([.]).*\1/bW; /[1-9]/ {s/$/\tOK/; b}; :W; s/$/\tWRONG/' file
1       OK
1.5     OK
.5      OK
0.5     OK
+1      OK
.50     OK
0.5000  OK
+100    OK
+.5     OK
+1.3    OK
0.5a000 WRONG
+100b   WRONG
+.5;    WRONG
+z1.3   WRONG
-1      WRONG
-.5     WRONG
-1.3    WRONG
.0      WRONG
0.      WRONG
0.0     WRONG
+0      WRONG
+.0     WRONG
+0      WRONG
+0.0    WRONG
.0.5    WRONG
.1.1    WRONG
.1.3.5  WRONG


You could run the sedwith a "here-string" like
Code:
$ set -- .1.3.5
$ sed -r '/[^0-9+.]/bW; /([.]).*\1/bW; /[1-9]/ {s/$/\tOK/; b}; :W; s/$/\tWRONG/' <<< $1
.1.3.5    WRONG

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies

2. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

3. Shell Programming and Scripting

Using regex in sed to validate the length of an entry

I'm having trouble using sed to validate the length of an entry. I want to have a user enter a phone number of either length 7, 10 or 11. Only numbers are allowed. Does anyone know how to do this? Here's the code I have so far. It only validates that numbers are entered but not the length. ... (1 Reply)
Discussion started by: snag49ers
1 Replies

4. Shell Programming and Scripting

Converting perl regex to sed regex

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)
Discussion started by: suntzu
1 Replies

5. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

6. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

7. Shell Programming and Scripting

Resolving a parameter which is passed as parameter

Hi, I have the following files. ->cat scr.sh export TMP_DIR=/home/user/folder1 export TMP_DIR_2=/home/user/folder2 while read line do cat "$line" done<file_list.dat ------------------------ -> cat file_list.dat $TMP_DIR/file1.txt $TMP_DIR_2/file2.txt --------------------------- -> cat... (6 Replies)
Discussion started by: barath
6 Replies

8. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

9. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

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)
Discussion started by: RobbieTheK
0 Replies
indicator(1F)							   FMLI Commands						     indicator(1F)

NAME
indicator - display application specific alarms and/or the "working" indicator SYNOPSIS
indicator [-b [n]] [-c column] [-l length] [-o] [-w] [string]... DESCRIPTION
The indicator function displays application specific alarms or the "working" indicator, or both, on the FMLI banner line. The argument string is a string to be displayed on the banner line, and should always be the last argument given. Note that string is not automatically cleared from the banner line. OPTIONS
-bn The -b option rings the terminal bell n times, where n is an integer from 1 to 10. The default value is 1. If the terminal has no bell, the screen is flashed instead, if possible. -c column The -c option defines the column of the banner line at which to start the indicator string. The argument column must be an integer from 0 to DISPLAYW-1. If the -c option is not used, column defaults to 0 . -l length The -l option defines the maximum length of the string displayed. If string is longer than length characters, it will be trun- cated. The argument length must be an integer from 1 to DISPLAYW. If the -l option is not used, length defaults to DISPLAYW. Note that if string doesn't fit it will be truncated. -o The -o option causes indicator to duplicate its output to stdout . -w The -w option turns on the "working" indicator. EXAMPLES
Example 1 A sample output of the indicator command. When the value entered in a form field is invalid, the following use of indicator will ring the bell three times and display the word WRONG starting at column 1 of the banner line. invalidmsg=`indicator -b 3 -c 1 "WRONG"` To clear the indicator after telling the user the entry is wrong: invalidmsg=`indicator -b 9 -c 1 "WRONG"; sleep 3; indicator -c 1 " "` In this example the value of invalidmsg (in this case the default value Input is not valid), still appears on the FMLI message line. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) SunOS 5.11 5 Jul 1990 indicator(1F)
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy