I want to compare to alphanumeric value in a unix shell script.

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I want to compare to alphanumeric value in a unix shell script.
# 8  
Old 08-22-2013
Originally Posted by Nsharma3006
Do you have any idea how to capture value of hostname in variable and so that i can use that variable to compare my value in further script.
Yes, depending on your OS (you haven't told what you use so far) this might work:


Originally Posted by Nsharma3006
can you share ur gtalk id where i can connect you.
I need to resolve this issue on urgent basis your help will really help me.
First, technical discussion are carried out here, nowhere else. The reason is that what i write for you might help somebody else with a similar problem in the future.

Second: we have here, out of principle, no "urgent" problems. If you need professional help from an expert you should consider hiring such a person - i do this for a living, like many others here too. Please understand that we do volunteer work here and if a problem is urgent for you it isn't urgent for us.

Finally, before you add yet another question: what should your script do, in which environment should it run, which input will it get and what have you written so far. Please give a complete answer to this, not only a line and, once this is debugged, another line with another problem. This way you might get answers to detail questions but not suggestions on how you might write the script better overall.

I hope this helps.

# 9  
Old 08-22-2013
Thanks Alot bakunin my this above requirement is working fine with all your valuable input.

Last edited by Nsharma3006; 08-25-2013 at 05:51 PM..
# 10  
Old 08-23-2013
Originally Posted by Nsharma3006

exist and are not empty.
To test for existence is easy, but better is to test if they are readable, because a file sitting there without being readable will not help you:


if [ -r "$file" ] ; then
     echo "file $file exists and is readable"
     echo "file $file either does not exist or is not readable"

To check if it is empty is more complicated, but i think you do not even need that: (try to) read from the file what you need to read and if some vital information is missing, issue an error message.

For instance, suppose you need 3 lines, labeled "first", "second", "third" to hold some declaration, like the following:


This example code will check that and complain if one line is missing:



if [ ! -r "$infile" ] ; then
     echo "ERROR: file $file is not readable or does not exist"
     exit 2

while IFS="=" read item value ; do
     case "$item" in



               echo "Warning: skipping unintelligible line \"${item}=${value}"
done < "$infile"

if [ "$first" = "" -o "$second" = "" -o "$third" = "" ] ; then
     echo "ERROR: not all values were passed"

I hope this helps.

# 11  
Old 08-23-2013
how to check a file <filename> exist at a particular path <cm/ims/dev> and not empty


I need to write a unix shell script to write

Last edited by Nsharma3006; 08-25-2013 at 05:52 PM..
# 12  
Old 08-23-2013
if [[ -f cm/ims/dev/filename ]]; then
# 13  
Old 08-23-2013
if [ "$a" = "$h" ]; then
  echo "hostname $a is same"
  echo "hostname $a is not same"
if [ "$b" = "$h" ]; then
  echo "hostname is same"
  echo "hostname is not same"

---------- Post updated at 03:23 PM ---------- Previous update was at 03:09 PM ----------

i am not sure but give a try to this code.
if [ -e $FILEPATH/$FILENAME ]; then
    if [ -n "$FILEDATA" ]; then
        echo "not empty"
        echo "empty"
    echo "file doesnot exist"

# 14  
Old 08-23-2013
Requirement is to check file and enter in the loop accordingly

however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value

Last edited by Nsharma3006; 08-25-2013 at 05:53 PM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to compare numbers in alphanumeric string

Hi, I will be having file names like below, 1420SP1.01804 1420SP1.01805D 1420SP1.01805 1420SP1.01806D 1420SP1.01806 1420SP1.01901D 1420SP1.01901 1420SP1.01902D 1420SP1.01902 1420SP1.01903D 1420SP1.01903 1420SP1.01904 1420SP1.01905 From this, I need to list file names which is... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

2. Shell Programming and Scripting

Howto compare the columns of 2 diff tables of 2 different schemas in UNIX shell script

HI All, I am new to Unix shell scripts.. Could you please post the unix shell script for for the below request., There are two different tables(sample1, sample2) in different schemas(s_schema1, s_schema2). Unix shell script to compare the columns of two different tables of two... (2 Replies)
Discussion started by: Rajkumar Gopal
2 Replies

3. Shell Programming and Scripting

ksh to compare alphanumeric values from 2 files

Hi there, I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message. lspv_pre.out hdisk0 00c39eaa451144dd rootvg active hdisk1 00c39eaa45223322 ... (3 Replies)
Discussion started by: mbak
3 Replies

4. Shell Programming and Scripting

Shell Script to Compare Two Files

I have a directory with about 6 files that we receive regularly. these 6 files contain information for 3 different units, 2 for each unit. files related to a specific unit are named similarly with a change in number at the end of the file. the numbers should be sequential. for each grouping of... (3 Replies)
Discussion started by: scriptman237
3 Replies

5. Shell Programming and Scripting

Comparing Alphanumeric Variables in Shell Script

Can someone please help me out here? I have strings similar to aafafaff45,29.34.942.45,edfdfafa that i want to compare to another similar string to check if they are the same. my script isn't working. ONE="aafafaff45,29.34.942.45,edfdfafa" TWO="ddfafagfa,87.57.942.45,afafafff" if ONE is... (5 Replies)
Discussion started by: SkySmart
5 Replies

6. Shell Programming and Scripting

compare dats in the shell script.

grep "HP_nv6005ud" mail_log.log | awk '{print $2}' >raju.log if then grep "$testdate" raju.log if Hi in the above script $2 gives rge today date. and $ydate is yesterdays date. not in the if condition i need to compare both the dates. Please help me in this. Thanks in... (7 Replies)
Discussion started by: intiraju
7 Replies

7. Shell Programming and Scripting

how to compare two lines using shell script?

how to compare two lines using shell script? (1 Reply)
Discussion started by: suman_dba1
1 Replies

8. Shell Programming and Scripting

String compare in shell script

Iam trying to compare the string in if else... but some how its not working following is the code On executing the above one its giving a error message ': bad number' in the above parameter l & k are numbers and dbfiles and patchefiles are array If i do echo ift working fine ... (2 Replies)
Discussion started by: kiranlalka
2 Replies

9. Shell Programming and Scripting

How to compare the dates in shell script

Hi How to compare created or modified date of two files help needed thanks Vajiramani :) (9 Replies)
Discussion started by: vaji
9 Replies

10. Shell Programming and Scripting

shell script cant recognize if else compare

hi I face the problem the if else statement dint return correct result for me my script as below: #!/bin/ksh sqlplus -s /nolog <<EOF connect databaseuser/password column num new_value num format 9999 set head off select count(*) num from table1; exit num EOF if ; then echo "$?"... (6 Replies)
Discussion started by: jaseloh
6 Replies
Login or Register to Ask a Question