Loop logic, enter into respective IF as per enter input file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Loop logic, enter into respective IF as per enter input file name
# 1  
Old 08-24-2013
Loop logic, enter into respective IF as per enter input file name

have three big data file, however I just need to see the mentioned below one line form the all the file which has SERVER_CONNECTION Value
File 1
Code:
export SERVER_CONNECTION=//dvlna002:10001/SmartServer

File2
Code:
export SERVER_CONNECTION=//[SERVER_HOSTNAME]/SmartServer

File3
Code:
export SERVER_CONNECTION=//dvlna003/SmartServer

One varaible i.e Test=dvlna002

now my requirement is to compare the values
Condition 1 for file1 : compare variable "Test" with "dvlna002" (this come from file 1 by grep command see the script ) if matches return "SAME" else "NOT SAME"
Condition 2 for file2: compare variable "Test" with "[SERVER" (this come from file 2 by grep command see the script) if matches return "SAME" else "NOT SAME"
Condition 3 for file3: compare variable "Test" with "dvlna003" (this come from file 3 by grep command see the script) if matches return "SAME" else "NOT SAME"

Output Result should be
Condition 1 >> SAME
Condition 2 >> NOT SAME
Condition 3 >> NOT SAME

I want to first write in the script that entre the file name and on the basis of file name entred by user it should go to the respective IF condition
Example : like I entered File 1 then it should only go to Condition 1 which check for Test = "dvlna002" , if it satisfy it just send me output of "SAME"

As of now I have written the script which is like this, I am unable to but the logic where it decide on which if condition it should go
Code:
#!/bin/sh 
Test=dvlna002 
echo "enter the file name from File1, file2, file3" 
read filename 
a= grep "SERVER_CONNECTION" file1 |cut -c 28-35 |tail -1 
b= grep "SERVER_CONNECTION" file2 |cut -c 28-35 |tail -1 
c= grep "SERVER_CONNECTION" file3 |cut -c 28-35 |tail -1 
if [ "$a" = "$Test" ]; then 
echo "same" 
else 
echo "not same" 
fi 
if [ "$b" = "$Test" ]; then 
echo "same" 
else 
echo "not same" 
fi 
if [ "$c" = "$Test" ]; then 
echo "same" 
else


Last edited by Scrutinizer; 08-24-2013 at 02:56 PM.. Reason: code tags
# 2  
Old 08-24-2013
I'm not sure I understand your logics, but maybe you want to try sth like
Code:
if [ "$a" = "$Test" ] && [ "$filename" = "File1" ]; then

or, maybe, a case "$filename" statement?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect command to send the user input enter or ctrl+c

Hey All, I am writing one script using expect, that script which is used in spawn will accepts only 1. Enter 2. Ctrl+c Press Control-C to exit, Enter to proceed. Could some one share some thoughts to send the above user inputs in linux expect block ? Thanks, Sam (0 Replies)
Discussion started by: SCHITIMA
0 Replies

2. Shell Programming and Scripting

Automatically enter input in command line

Hi, This is a script which to create an opvn user, I want which answer automatically to a certain part so, I try this, it works without the red part but I must type manually.. : #!/bin/bash ## Environnement ## LC_ALL=C ## Paths ## rsa_dir="etc/openvpn/easy-rsa"... (10 Replies)
Discussion started by: Arnaudh78
10 Replies

3. Shell Programming and Scripting

Input password to bash script, save, and enter when needed

I am looking for a way to start a script and have it prompt for a password that will be used later on in the script to SSH to another host and to SFTP. I don't want the password to be hard coded. Below is my script with the actual IP's and usernames removed. #!/usr/bin/expect -f... (2 Replies)
Discussion started by: jbrass
2 Replies

4. Shell Programming and Scripting

View on screen text file and enter input

Is the below correct syntax for if the user enters something other than "GJB2 or MECP2, or PHOX2B", then they are shown on the screen format.txt and allowed to enter in one of those formats? Thank you :). Basically, the user can see which formats are allowed and enter a variant while viewing... (7 Replies)
Discussion started by: cmccabe
7 Replies

5. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

6. Shell Programming and Scripting

Enter an input and reference another line in ksh script

Hi I have a file like so: Code: Frank Peter Tony Robert Mike 1 2 3 4 5 5 4 2 3 1 4 3 1 5 2 My out should look like this: Peter Tony Mike and so on.... I have the first part done to ask the user to... (8 Replies)
Discussion started by: bombcan1
8 Replies

7. Shell Programming and Scripting

enter key or carriage return as input in perl

hi experts Question in perl i'm creating a script to take from user a different inputs one of them is the carriage return .. so that i want to make an if condition if the user hit enter key the user will go to previous step it something like that chomp ($input = <STDIN>); if ($input =~... (3 Replies)
Discussion started by: doubando
3 Replies

8. Shell Programming and Scripting

using read to enter the input at runtime

Hi I am stucked in the below script .I want to input with yes/no from the user and then execute the code inside if but it is not working .I just need the logic as where I am wrong so that i can use the same in my work . then echo "Hi All" fi ]. Please suugest . (4 Replies)
Discussion started by: mani_isha
4 Replies

9. Shell Programming and Scripting

how to input answer (enter) if output contains a string?

how to wrote a script that reads an input from the reader (dir name) and then answer yes to all questions in the script unless the answer to any of the questions contains a certain string? example: $] script.sh dir_name $] question_1: (answer should be y right after the question is echoed,... (3 Replies)
Discussion started by: faizlo
3 Replies

10. Shell Programming and Scripting

BASH: Any Way to Get User Input Without Requiring Them to Hit the Enter Key?

I'm working on making a menu system on an HP-UX box with Bash on it. The old menu system presents the users with a standard text menu with numbers to make selections. I'm re-working the system and I would like to provide something more akin to iterative search in Emacs. I have a list of 28... (2 Replies)
Discussion started by: deckard
2 Replies
Login or Register to Ask a Question