Visit Our UNIX and Linux User Community

Check if string contains substring surrounded by numbers

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Check if string contains substring surrounded by numbers
# 1  
Old 08-21-2019
Check if string contains substring surrounded by numbers


I have a process that generates strings.
I would like to check each string and search for substring which contains the letter 'E' surrounded by numbers (both sides of the letter 'E').

few examples:

AA4E7012A2 - contains E surrounded by numbers
FE18274012 - does not contain E surrounded by numbers
49EFCE8FC3 - does not contain E surrounded by numbers
F3DCD73EA1 - does not contain E surrounded by numbers
957FF564E7 - contains E surrounded by numbers

I tried few options of using the next check without much success: ^[[:digit:]]*[[:alpha:]]*[[:digit:]]*$

please advise.


Last edited by rbatte1; 08-21-2019 at 02:25 PM.. Reason: Added ICODE tags
# 2  
Old 08-21-2019

Last edited by rdrtx1; 02-18-2020 at 09:03 PM..
These 2 Users Gave Thanks to rdrtx1 For This Post:
# 3  
Old 08-21-2019
Please use code and icode tags.
Also, shell, operating system and utilities which are to be used would help us help you.
Your coding effort is also encouraged.

Here is gnu grep from linux box
grep -E "+[0-9]E[0-9]+" input

Where input is a file which contains your example data.

Hope that helps
# 4  
Old 08-21-2019
What happens when there is one E surrounded by numbers and one that is not?

Out of curiosity, is this significant? : The letters are between A and F. Are you certain those are not hexadecimal numbers ?

Previous Thread | Next Thread
Test Your Knowledge in Computers #48
Difficulty: Easy
Alan Turing is considered to be the 'Father of Cryptography'.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Check if a string starts with certain values and ends with numbers

This is very basic. Yet Iam struggling to get the right pattern for my check. Apologize in advance to ask a very lame question. I have to validate if a value of the variable starts with "efgh" and followed by 6 numbers. Var1="efgh234567" The condition Iam trying to achieve is similar to... (6 Replies)
Discussion started by: deepakwins
6 Replies

3. Shell Programming and Scripting

Substring check in IF condition in shell script

I want to check if the string has the substring in IF condition then process... i tried below but not working if ]; then ............. field can be "reserved1" ....reservedn / fillspaces1 ... fillspacesn (4 Replies)
Discussion started by: greenworld123
4 Replies

4. Programming

check substring

hi everyone I have a C program where I have a line and I want to check if the line contains a string.The line is stored in a buffer.How can I do that? Can I consider the whole line as a string and check for a substring?And if so what's the most efficient way to achieve it? (1 Reply)
Discussion started by: vlm
1 Replies

5. Programming

Check for a substring

Hi, I have a macro which I use with ROOT. In this macro I want to check if a part of string exist so I can ignore it inside a loop. So, inside a loop I want to have something like: if (string == "pre_ti_data_bdt*" || string == "pre_ti_data_nn*") continue;but of course I cannot use * in this... (11 Replies)
Discussion started by: faizlo
11 Replies

6. Shell Programming and Scripting

Help with string and substring also I/O

#!/bin/sh PRINTF=/usr/bin/printf PASSWD=/etc/passwd $PRINTF "Enter a UserID\n" read USERID if ; then $PRINTF "$USERID does not exist, please contact IT service\n" exit 1 fi USERHOME=`grep "^$USERID:" $PASSWD | awk -F : '{print $6}'` USERSHELL=`grep "^$USERID:"... (1 Reply)
Discussion started by: ikeQ
1 Replies

7. Shell Programming and Scripting

get substring from string

Hi All, Problem Description: XML_REP_REQUEST=`CONCSUB "$LOGIN" "SQLAP" "$RESP_NAME" "$USRNM" WAIT="Y" "CONCURRENT" "APPLICATION_SHORT_NAME" "CP_SHORT_NAME"` echo Report Request: $XML_REP_REQUEST --to print value in log file While execution the value of 'XML_REP_REQUEST' is 'Prozess... (5 Replies)
Discussion started by: suman.g
5 Replies

8. UNIX for Dummies Questions & Answers

How to get the substring from the string

Hi All, Can anybody help me to get the substring from the given string. (3 Replies)
Discussion started by: Anshu
3 Replies

9. Shell Programming and Scripting

getting a substring from a string

hi all, I am trying to extract SUBSTRINGS out of a string using ksh. The string is "SAPR3K.FD0.FA.TJ.B0010.T050302" I tried using a= `expr substr $stringZ 1 2` which is giving me a syntax error, donno why?? any ideas why its not working?? I also tried echo "welcome" | awk '{... (3 Replies)
Discussion started by: maradona
3 Replies

10. Programming

can i get a substring from a string?

for example, the string a is "abcdefg", can i get a substring "bcd" (from ato a) from string a? thank you (4 Replies)
Discussion started by: dell9
4 Replies

Featured Tech Videos