anchoring regex using case and ksh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers anchoring regex using case and ksh
# 1  
Old 07-29-2008
anchoring regex using case and ksh

Outside this process I built a file containing snmp response filtering for hostname, model type and ios version.

I want to get a count across the network of those devices running 11.x code, 12.0 mainline, 12.0 T train and above, 12.1 and above and OS levels.

This works ok .. but its cheap Smilie

How can use case ? the obvious didnt work. I guess I dont know how to anchor the regex.

grep " 11\.[0-9]" seedfile$hf > 11_$hf
grep " 12\.0" seedfile$hf | grep "]$" > 12_0_$hf
grep " 12\.0" seedfile$hf | grep -v "]$" > 12_1_$hf
grep " 12\.[1-9]" seedfile$hf >> 12_1_$hf
grep " [1-9]\.[1-9]\{1,\}" seedfile$hf > 7_$hf
# 2  
Old 07-30-2008
I don't understand what you want. Those grep's are not anchored. Smilie
# 3  
Old 07-31-2008
Instead of doing all the greps, Id rather read through the file. I dont want to use ifs, I want to use case. Ifs are shown for a psuedo code explaination.

while read ip model ios hostname
do
case $ios in

if $ios is 11.0 print I have 11.0
if $ios is 12.0 mainline print I have 12.0
if $ios is 12.0 not mainline print I have 12.0 T or above
if $ios is single digit followed by a single digit it must be an os print I have an os

esac
done < seedfile
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about REGEX Patterns and Case Sensitivity?

Hello All, I'm in the middle of a script and I'm doing some checks with REGEX (i.e. using the '"shopt -s nocasematch" that at least the first one should print "FALSE" but it prints "TRUE"..? For Example: #!/bin/bash MY_VAR="HELLO" ### This prints "TRUE" PATTERN_1="^*" if ] then... (5 Replies)
Discussion started by: mrm5102
5 Replies

2. Shell Programming and Scripting

Using an array with a case statement in KSH

Hi, I'm really new ro shell scripting (actually any kind of programming) and am pretty sure I'm making a pretty basic error here but I can't for the life of me figure it out. What I'm trying to do is get an array working with a case statement in a KSH script. The code is as follows: ... (3 Replies)
Discussion started by: SReilly
3 Replies

3. Shell Programming and Scripting

lower to upper case in ksh

What is the command to change the contents of a file to UPPER case. Here in this file below you see some characters are Sp, Ch 1200812270046581 22885072800000652 B86860003OLFXXX592123320081227 22885029800000652 B86860003ODL-Sp592123420081227 22885093700000652-B94030001ODL-Ch592123520081227... (4 Replies)
Discussion started by: kshuser
4 Replies

4. Shell Programming and Scripting

[BASH] recognise new line regex in case statement

Hi, I'm trying to write a routine to parse a file that contains data that will be read into arrays. The file is composed of labels to identify data types and arbitrary lines of data with the usual remarks and empty new lines as is common with config files. The initial pass is built as so:... (3 Replies)
Discussion started by: ASGR
3 Replies

5. Shell Programming and Scripting

bash regex =~ case insensetive, possible?

It can get very annoying that bash regex =~ is case-sensetive, is there a way to set it to be case-insensetive? if ]; then echo match else echo no match fi (8 Replies)
Discussion started by: TehOne
8 Replies

6. UNIX for Dummies Questions & Answers

ksh case structure

Hello Experts, I ve been trying to build another shell where I am using the following code. transact="tv5cpc1" case "$transact" in "...cp..") xActType="" ;; "...de..") xActType="sp_dep" ;; "...ep..") xActType="sp_epa" ;; "....v.") ... (4 Replies)
Discussion started by: hkansal
4 Replies

7. Shell Programming and Scripting

ksh case statement

I am trying to write a ksh script using the case statement to select certain directories to remove. The directories that I am looking for are in the following format 2008-10-10. I want to exclude all other files/directories that contain anything other the 4 digit year,a dash, 2 digit month, a... (2 Replies)
Discussion started by: dgilc
2 Replies

8. Shell Programming and Scripting

How to specify 'not case sensitive' in regex (nawk, sed, patern expencions)?

Is it possible to make the search in regular exprecion or in matching parts of sed, nawk and others to IGNORE the case of the search string? I mean, like if used 'grep' with -i option: > grep -i "abc" file I would like to be able to do the same, say, by nawk: > nawk '/abc/ {print $0}'... (4 Replies)
Discussion started by: alex_5161
4 Replies

9. Shell Programming and Scripting

ksh case problem

I'm trying to run a ksh script with a case condition to handle parameters. #!/bin/ksh db_start(){ *code } db_shut(){ *code } case "$1" in up) db_start TRNG ;; down) db_shut TRNG ;; *) echo "Usage: $0 { up | down }" (3 Replies)
Discussion started by: digiteck
3 Replies

10. Shell Programming and Scripting

Case (ksh)

Isn't any "NOT" operator that can be used in the case construction like : case $VAR (NOT) in option1 | option2 | option 3...) COMMAND ;; esac Or something similiar to the "default" from switch, so I could at least do something like this: case $VAR in ... (2 Replies)
Discussion started by: 435 Gavea
2 Replies
Login or Register to Ask a Question