Case statement/sed command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Case statement/sed command
# 1  
Old 11-13-2008
Case statement/sed command

The file dbnames.txt has 5 columns, what i'm trying to do is that when the fifth column equals A, store in the variable "access" the word, "admin access". If it equals B, then "business access" etc. I think their is a problem with my sed command, because it is not substibstituting the words correctly. Any ideas?

thanks,

ross_one

tput cup 13 0; echo "Enter your name:"
tput cup 13 16; read name
location=`find dbnames.txt`
x=`grep -c "$name" "$location"`
if [ $x -gt 0 ]
then
tput cup 15 0; echo "Name found!"
grep "$name" "$location" | cut -f 1,2,3,4,5 -d, | tr ',' ':' > temp.txt
y=`grep -F "$name" "temp.txt" | cut -f5 -d:`
case "$y" in

"A")
access="Administrator access" ;;
"B")
access="Business access" ;
"C")
access="Secretary access" ;;
*)
access="General access" ;;
esac

sed -e "s/A/$access/i" -e "s/B/$access/i" -e "s/S/$access/i" -e "s/G/$access/i" < temp.txt > test2.txt

cat test2.txt

fi

Last edited by ross_one; 11-13-2008 at 12:01 PM..
# 2  
Old 11-14-2008
Are you sure $access is being set to the correct value? Try echoing it just before your sed script. Add other echos as required to help you debug, e.g. to make sure $y is being set correctly, etc.

You are missing one semi-colon in your case statement.

Also consider that using s///i means case is ignored, so it might change A into "Administrator access", and then the s/S/$access/i would change it into AdminiAdministrator accesstrator access.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

2. Homework & Coursework Questions

Case Statement

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hey, guys I really need some help with a project. "Write a shell program that examines the command line... (8 Replies)
Discussion started by: sk192010`
8 Replies

3. Shell Programming and Scripting

making sed command case insensitive

i have something like this in a file cat onlytables.sql create table NextID ( id int auto_increment, zoneID int, entityName varchar(64), nextID int, lastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary... (6 Replies)
Discussion started by: vivek d r
6 Replies

4. Shell Programming and Scripting

Case statement

Hello, The standard case statement :- case "$1" in "IE0263") commands;; "IE0264") commands;; esac is it possible to have :- case "$1" in "IE0263" OR "IE0878") commands;; "IE0264") commands;; esac Thanks (4 Replies)
Discussion started by: jmahal
4 Replies

5. 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

6. Shell Programming and Scripting

help with case statement

I am writing a script to pull diskspace information from our servers. Here is the script that I wrote: #!/bin/ksh for host in `cat /oper/hosts/esc.misc` do ssh -q -o ConnectTimeout=10 operator@$host df -h|grep "/dev/" |egrep '8%|9%|100%' | awk '{print H " " "at " $5 " with " $4 "... (1 Reply)
Discussion started by: rkruck
1 Replies

7. UNIX for Dummies Questions & Answers

CASE statement

Hi, I am writing a bash shell script. My script has a few user defined parameters. When the script runs the first thing it does is make sure that these parameters are valid. One of the parameters is called YEAR. A valid input for YEAR can be 1997-2000. One way I have come up with to ensure... (3 Replies)
Discussion started by: msb65
3 Replies

8. Shell Programming and Scripting

case statement

Hi all, I think i'm asking a sqtupid question here.. i'm using case sttament, what is the syntax or symbol for "or"? I thought was || here a quick sample of my case statment echo "Would you like to update your detail ?" read response case $response in ... (2 Replies)
Discussion started by: c00kie88
2 Replies

9. UNIX for Dummies Questions & Answers

If or Case Statement

I want to write a program with the following variables: a=7000 b=24000 c=613.8 The user can enter two words: Vivid or Blue for example. The challenge is that the user might not want to write the words the way they appear. The user can write V or v or vivid or Vivid or write Blue or blue, or B,... (1 Reply)
Discussion started by: Ernst
1 Replies

10. Shell Programming and Scripting

case statement

Hi all, is it possible to create a 'dynamic' case statement. ie select option in `ls` do case satement depending on results of the above `ls` done I hope I have explained this ok! Thanks Helen (1 Reply)
Discussion started by: Bab00shka
1 Replies
Login or Register to Ask a Question