Help needed in case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed in case
# 8  
Old 11-28-2013
OK, but how can we automate the script if we don't know the associations?
Is there another text file that contains the associations?
# 9  
Old 11-28-2013
No.we can create a text file.We can hard code the ip address with the snedmail ?
# 10  
Old 11-28-2013
Assuming your file.txt contains the following lines:
Code:
"25319","45162","TEST","ADMIN","127.3.3.1","select * from test","2013-11-27 19:38:28","2013-11-27 19:38:28",11
"25319","45162","TEST","ADMIN","127.3.3.4","select * from test","2013-11-27 19:38:28","2013-11-27 19:38:28",11

Assuming that there are no embedded commas in the filed values.
Something like this might work for you:
Code:
_ips=( 
  tool1_127.3.3.1
  tool1_127.3.3.2
  tool1_127.3.3.3 
  tool2_127.3.3.4
  tool2_127.3.3.5
  tool2_127.3.3.6  
  )


while IFS=, read j j j j _ip j; do
  _ip=${_ip//\"}
  for _t_ip in "${_ips[@]}"; do
    [[ $_ip == ${_t_ip##*_} ]] && {
      echo send mail -- connection -- append from "${_t_ip%_*}"
      break 
      }
  done
done < file.txt

I get the following output:
Code:
$ ./s
send mail -- connection -- append from tool1
send mail -- connection -- append from tool2

Remove the echo if the output matches your expectations.

Last edited by radoulov; 11-28-2013 at 05:44 AM..
# 11  
Old 11-28-2013
Thanks a lot..!! Radoulov.

I guess we are not receiving the file.txt full line with this detail

Code:
"25319","45162","TEST","ADMIN","127.3.3.1","select * from test","2013-11-27 19:38:28","2013-11-27 19:38:28",11"25319","45162","TEST","ADMIN","127.3.3.4","select * from test","2013-11-27 19:38:28","2013-11-27 19:38:28",11

Can we add if ip address is this,this will append mail with full detail like above format in a file.
# 12  
Old 11-28-2013
In this case, you could use something like this:
Code:
_ips=( 
  tool1_127.3.3.1
  tool1_127.3.3.2
  tool1_127.3.3.3 
  tool2_127.3.3.4
  tool2_127.3.3.5
  tool2_127.3.3.6  
  )

  
for _t_ip in "${_ips[@]}"; do
  grep -w "${_t_ip##*_}" file.txt > /dev/null &&
      echo send mail -- connection -- append from "${_t_ip%_*}"
done

# 13  
Old 11-28-2013
To get the entire line containing the IP:
Code:
_ips=(
  tool1_127.3.3.1
  tool1_127.3.3.2
  tool1_127.3.3.3
  tool2_127.3.3.4
  tool2_127.3.3.5
  tool2_127.3.3.6
  )


for _t_ip in "${_ips[@]}"; do
  _record=$(
    grep -w "${_t_ip##*_}" file.txt
    ) &&
    echo send mail -- connection -- append from "${_t_ip%_*}" -- detail "$_record"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change first letter of a word from lower case to upper case

Hi all, I am trying to find a way to change first letter in a word from lower case to upper case. It should be done for each first word in text or in paragraph, and also for each word after punctuation like . ; : ! ?I found the following command sed -i 's/\s*./\U&\E/g' $@ filenamebut... (7 Replies)
Discussion started by: georgi58
7 Replies

2. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

3. Shell Programming and Scripting

sed ignoring case for search but respecting case for subtitute

Hi I want to make string substitution ignoring case for search but respecting case for subtitute. Ex changing all occurences of "original" in a file to "substitute": original becomes substitute Origninal becomes Substitute ORIGINAL becomes SUBSTITUTE I know this a little special but it's not... (1 Reply)
Discussion started by: kmchen
1 Replies

4. Shell Programming and Scripting

data array needs to change upper case to lower case

Hi all, i have a data array as followes. ARRAY=DFSG345GGG ARRAY=234FDFG090 ARRAY=VDFVGBGHH so on.......... i need all english letters to be change to lower case. So i am expecting to see ARRAY=dfsg345ggg ARRAY=234fdfg090 ARRAY=vdfvgbghh so on........ If i have to copy this data in... (8 Replies)
Discussion started by: usustarr
8 Replies

5. Shell Programming and Scripting

Help needed in Switch Case

Hi Experts team, i wish to use switch case in unix. my req is case $code in 1111) echo "1111" 1112) echo "1112" *) echo "default" esac see eventhough for particular case 1111 , it is always execute the default statement *), if i code like this. How can handle... (2 Replies)
Discussion started by: spkandy
2 Replies

6. Shell Programming and Scripting

Help needed in switch case handling in UNIX

Hi, In below code, i am expecting the output has Bye Bye But i am getting has Bye Hi Code: #!/usr/bin/bash var="Hi" cat txt.txt | while read var1 do next="Bye" case $var in Hi) (1 Reply)
Discussion started by: Balamani
1 Replies

7. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

8. Shell Programming and Scripting

help needed in using case statement

Hi, I have a script as below: ....................................................................... rpttxt() { name="$*" awk '/'"${name}"'/ {print $2$3$4 }' file_1.txt } title="`rpttxt "TITLE"`" ......................................................................... The... (0 Replies)
Discussion started by: jisha
0 Replies

9. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question