Can i use grep to check variable content correctnes?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can i use grep to check variable content correctnes?
# 1  
Old 12-19-2010
Can i use grep to check variable content correctnes?

I need to know if is possible to use grep to check content of a local variable, for eg. i use read index and i want to check if the index i read is in correct form, how do i do that i tried with grep but i get errors all the time dont know how to make it work.. thanks!
# 2  
Old 12-19-2010
A case statement usually works best for this purpose.. What have you tried so far. Can you give an example?
# 3  
Old 12-19-2010
Using grep, or any external command, to operate on a single line is very wasteful. Do that in a loop and you'll wonder what's making your script so slow...

Depending on your shell there's many ways to check what's in a variable. Case statements are one way. And if you have bash 3 or newer, it supports full-blown built-in regexes.
# 4  
Old 12-19-2010
And so does ksh93,,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check content

I would like to write a shell script to do the following , would advise how to make it ? very thanks 1. Connect LDAP server ( Id : user , password : pass ) 2. check the field "user_account_create_date" in the LDAP server , the format of data in this field in LDAP is ABC20130922 ( 22 Sep ,... (3 Replies)
Discussion started by: ust3
3 Replies

2. Shell Programming and Scripting

Check content of file

Hi All, I m very new to unix...i jus want to chk the content of file. ma requirement is if file has a content then display it else dont display or something pls specify which loop shalli use either for or while?? (20 Replies)
Discussion started by: navsan
20 Replies

3. Shell Programming and Scripting

korn shell: check the content of a string of a variable

hello, i have a variable which should have following content : var="value1" or var="value2" or var="value2:*" # example: value2:22 how can i check : - if the content is ok (value1 / value2* ) - the two options of "value2" when content is example "value2:22" , i want to split... (3 Replies)
Discussion started by: bora99
3 Replies

4. Shell Programming and Scripting

grep variable with tricky content

Hello, i have this issue: text="-8x7YTVNk2KiuY-PWG5zzzjB-zzw" string=-8x7YTVNk2KiuY-PWG5zzzjB-zzw echo $text | grep -v \'$string\' -8x7YTVNk2KiuY-PWG5zzzjB-zzw echo \'$string\' '-8x7YTVNk2KiuY-PWG5zzzjB-zzw' ..and ofcourse if I do like this : echo $text | grep -v $string grep: invalid... (5 Replies)
Discussion started by: black_fender
5 Replies

5. AIX

check web content - Ksh

Hi everybody! I wonder if I could see some text content of a website, via command line... That could be very helpful, in order to automatize a lot of projects im working on. thx a lot (2 Replies)
Discussion started by: Datinsky
2 Replies

6. Shell Programming and Scripting

Check file content type

I have a shell script that takes a file and uses "syncsort" to sort contents. I want to add a condition to check whether the input file is textual or binary format. If textual, the "syncsort" will be used to sort the files contents. Otherwise, the sorting process will be skipped. Note that the... (3 Replies)
Discussion started by: synthea
3 Replies

7. Shell Programming and Scripting

Bash : Check aphanumeric content in variable

Hello everyone, I'm trying the best way to implement a check on a variable ... in particular I need to assess the content of characters and numbers , I tried on various manuals bash scripting but I could not figure out how to do ... any help? (3 Replies)
Discussion started by: ionral
3 Replies

8. UNIX for Dummies Questions & Answers

check length content existence of variable

hi guys, im learning so be gentle... i'm wanting to write a script to read in a customer number. in order that the code is robust i want to check 1) the length of the value entered (4 characters) 2) that all characters entered are numeric between the values 1 to 3 3) that a value is... (1 Reply)
Discussion started by: skinnygav
1 Replies

9. Shell Programming and Scripting

To check the content of one file in another

Hi , I have a file called "X" . the content of X are X -- abc def and i have a file called "Y" , the content of Y are Y -- erty sdss s abc sfs def I need to check if the content of file X is contained in Y.Only unix (7 Replies)
Discussion started by: giri_luck
7 Replies

10. Shell Programming and Scripting

Content of Content of a variable!

I got a sample BASH script like this : $ cat test MYVAR=$1 DUMMY1="This is tricky" DUMMY2=24 echo $ $ ./test DUMMY1 ./test: line 5: This is tricky: syntax error in expression (error token is "is tricky") **I was expecting the output as "This is tricky", ah! but no luck **But... (2 Replies)
Discussion started by: jaduks
2 Replies
Login or Register to Ask a Question