[Solved] How to match xyz-mno-prq in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] How to match xyz-mno-prq in shell script?
# 1  
Old 07-08-2013
[Solved] How to match xyz-mno-prq in shell script?

I want to match variable with Point codes.
Code:
$Input == xyz-mno-pqr

x,y,z,m,n,o,p,q,r are numbers from 0 to 9.

It may or may not be there

eg

Code:
207-89-67

027-089-067

207-9-7

25-98-1

Like these inputs.

How to match these ?

Last edited by Scott; 07-08-2013 at 11:34 AM.. Reason: Code tags
# 2  
Old 07-08-2013
Please give us some context. Are you trying to match this format in an awk script, in a sed script, in a shell script, ...? What are you going to do after you successfully or unsuccessfully try to match the format?

What OS are you using? What shell do you want to use (or can we select a shell based on what you're trying to do)?

Do I correctly interpret your question to be: How do I verify that the string contained in a variable, field, or line is of the format x-y-z where x, y, and z each consist of one, two, or three decimal digits?
# 3  
Old 07-08-2013
Hi Don Cragun,

Thanks for your reply.
My issue is resolved/

Code:
bash-3.2$ cat raza
#!/usr/bin/bash
Input="$1"
echo "$Input"
if [[ $Input =~ ^[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}$ ]]
then
echo "HELLO"
PC=`echo "$Input" |sed -e 's/^[0]*//g'|sed -e's/-[0]*/-/g'`
grep -hw "$PC" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
else
echo "Hi"
egrep -h "$Input" /appl/voip/voipfiles/trunkgroups/tglastrun.mostrecent
fi
bash-3.2$

Moderator's Comments:
Mod Comment Please use CODE tags (not ICODE tags) when displaying multi-line code, input, and output.

Last edited by Don Cragun; 07-08-2013 at 03:41 PM.. Reason: Convert ICODE tags to CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Running a R script with in a shell script

Hi, I do have an R script named KO.R. Basically reads thousands of files, whose name has a pattern that differs at a portion of the file name, List.txt. Row_file1_mile.txt Row_file2_mile.txt Row_file3_mile.txt ... ... Row_file1000_mile.txt Below is a portion of my Rscript that reads... (4 Replies)
Discussion started by: Kanja
4 Replies

2. Shell Programming and Scripting

[Solved] Calling PL/SQL Block into Shell Script

Hi, i have one simple PL/SQL Block and i have saved it as .sql file, which i am trying to call from UNIX script. PL/SQL block structure CONNECT DB_NAME/PWD@Database whenever SQLERROR EXIT 1; Declare ..Variables... BEGIN --Code-- exception END; exit; I have save this block as... (3 Replies)
Discussion started by: abhii
3 Replies

3. Shell Programming and Scripting

[Solved] Shell script not working in crontab

Hi Iam running below script in crontab but its not working. #!/bin/sh cd /Scripts /usr/local/bin/expect -f /Scripts/bng_backup.exp /Scripts/data.txt tar -cf bngbackup.tar bngbackup ;gzip bngbackup.tar when iam running manually the output file is generating..but bngbackup.tar.gz file... (5 Replies)
Discussion started by: surender reddy
5 Replies

4. Solaris

[Solved] Using awk withing a shell script

I am trying to use an awk command within a ksh script but it is not working - I am able to run from command line with no problem. It does not err out - it just does not produce a file with final count. awk "{s+=$0} END {print s}" es.out > es.cntAny help would be greatly appreciated. Thanks (6 Replies)
Discussion started by: bjdamon
6 Replies

5. Shell Programming and Scripting

[Solved] Shell script help

Hi fellas, I have a file that contains text something like this SNAPSHOT snap-021ede4a vol-bc3f89c0 completed 2012-11-19T06:05:26+0000 100% 170495546006 850 Created by CreateImage(i-6adc0515) for ami-977dfafe from vol-bc3f89c0 TAG snapshot snap-021ede4a project PAC TAG snapshot... (5 Replies)
Discussion started by: Kashyap
5 Replies

6. Shell Programming and Scripting

run shell script under nohup directly [solved]

Hi, i am not able to run the loop in nohup directly. nohup 'for i in $(seq 10); do echo $i;./mscript.sh $i; done' can some one help me how to run this directly in nohup? ---------- Post updated 03-15-12 at 12:20 AM ---------- Previous update was 03-14-12 at 11:59 PM ---------- From... (0 Replies)
Discussion started by: johninweb
0 Replies

7. Shell Programming and Scripting

Need to find recursively all shell script in the /xyz directory

Pls. advise how to find or used grep recursively all shell script files. Some files doesnt have a .sh or .ksh extension name. find / -name "*" |xargs grep bin |grep sh ?? TIA (1 Reply)
Discussion started by: budz26
1 Replies

8. Shell Programming and Scripting

need to kill a number of processes with name "XYZ" at a time using shell script

Hi, when i grep for the process "XYZ" , there will be some good number of processes with that name, i want to kill all the these processes at a time using shell script? Any help needed for this action. Thanks Regards, Anil (6 Replies)
Discussion started by: anilmanepu
6 Replies

9. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

10. Shell Programming and Scripting

shell script: longest match from right?

Return the position of matched string from right, awk match can do from left only. e.g return pos 7 for search string "service" from "AA-service" or return the matched string "service", then caculate the string length. Thanks!. (3 Replies)
Discussion started by: honglus
3 Replies
Login or Register to Ask a Question