A shell script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A shell script question
# 1  
Old 11-24-2005
A shell script question

Hi,
I have a file say xmldir.conf. This is a flat file which contains the data in specific format not other then this. The format is
/backup/surjya/mvfile,noeof
/backup/surjya/mdbase,eof
/backup/surjya/mdbaseso
/backup/surjya/trial,hoeof
/backup/surjya/test,eof

The field before "," is directory names and field after "," is an attribute of the directory. I have written a shell script to list out the directory names from xmldir.conf file according to the attribute. Those names will be listed only if attribute is noeof or eof. If no attribute is there like 3rd row of the file then it is treated as also eof attribute.
Now my program is

#!/bin/sh
conffile=xmldir.conf
dir=`cut -d, -f1 xmldir.conf`
echo $dir
for dir1 in $dir
do
insertmode=`grep $dir1 $conffile | awk '{FS = ","} {print$2}'`
echo $insertmode
#echo $dir1 $insertmode
if [ $insertmode = "eof" -o $insertmode = "" ]
then
echo "It is eof dirs" $dir1
else if [ $insertmode = "noeof" ]
then
echo " It is noeof dirs" $dir1
fi
else
echo " It is neither of these"
fi
done

But it is not working. It fails when it is checked for rows without atribute. So please let me know how can I correct this.

Thanks
# 2  
Old 11-24-2005
Check this out and pick up from there.

Code:
[~/temp]$ cat surya.ksh
#! /bin/ksh

while read line
do
ATTR=$(echo $line | awk -F"," '{ print $2 }')
#echo -$ATTR-
if [[ "${ATTR}" == "noeof" ]] ; then
echo "noeof:$line"
elif [[ "${ATTR}" == "eof" || "${ATTR}" == "" ]] ; then
echo "eof:$line"
fi ;
done < surya.txt

Code:
[~/temp]$ cat surya.txt
/backup/surjya/mvfile,noeof
/backup/surjya/mdbase,eof
/backup/surjya/mdbaseso
/backup/surjya/trial,hoeof
/backup/surjya/test,eof

Code:
[~/temp]$ ./surya.ksh
noeof:/backup/surjya/mvfile,noeof
eof:/backup/surjya/mdbase,eof
eof:/backup/surjya/mdbaseso
eof:/backup/surjya/test,eof

vino
# 3  
Old 11-24-2005
Can you try this:

sed -n -e '/,/!p' -e '/,eof$/p' -e '/,noeof$/p' xmldir.conf|awk -F"," '{print $1}'

Would be really interested to know whether this is what you wanted.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

As per code it is getting matched. not sure why it assigning to cols=0. Any inputs please. Input : passed is shell.sh c tablename. if ; then cols=1 table=$2 else cols=0 table=$1 fi (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. Shell Programming and Scripting

Shell script question

Hi all, can you plz check whether the below code is correct & some inputs. I need to read the below file and process it. input : /home/ibm/var.txt urgent not urgent not needed. #!/usr/bin/ksh VAR=/home/ibm/var.txt if ] then (7 Replies)
Discussion started by: ramkumar15
7 Replies

3. Homework & Coursework Questions

question in shell script

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: Write a Bourne shell script which: • Has one command line argument. • If the command line argument is a... (5 Replies)
Discussion started by: abood1190
5 Replies

4. Homework & Coursework Questions

question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?! echo "enter a number " read n i=0 first=0 second=1 result=0 prime="true" echo –n " $first $second " while do result=`expr $first + $second` first=$second... (10 Replies)
Discussion started by: moonlips
10 Replies

5. Homework & Coursework Questions

Question on shell script

Hiiiiiiiiiiiii all, Please i want your help fast, the teacher gave us this assignment can u help me to write it? this is the question: Write a shell script to point all prime numbers from the fibonacci series of integer N? using Red hat Os Thanks all and waiting for ur answers... (1 Reply)
Discussion started by: moonlips
1 Replies

6. Shell Programming and Scripting

shell script question

I have script as following.. server_status= some command | grep "Total error: 0" if ; then echo " Server $(hostname) is Down" >>Result fi else echo " Server is OK on $(hostname)" >>Result the if command seems to be not working properly for some... (13 Replies)
Discussion started by: s_linux
13 Replies

7. Shell Programming and Scripting

shell script question

Hi, The contents of my file is below: Name,Location,Degree,Gender,Awards Robert,Philadelphia,Accounting,Male,5 Jane,Chicago,Business,Female,2 Allan,New York,Engineering,Male,6 Tom,Detroit,Computer Science,Male,10 Nancy,Milwaukee,Engineering,Female,4 I want to add a "ID" in the 1st line... (2 Replies)
Discussion started by: xinoo
2 Replies

8. Shell Programming and Scripting

Shell Script question

Hello Experts, I am new at this and need some help. I am looking for a delete command that allows me after I grep for the hostname to delete all the lines between two characters. for example I want to delete the first line all the way up to the } character host test019 { hardware ethernet... (10 Replies)
Discussion started by: ryanique
10 Replies

9. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

10. Shell Programming and Scripting

shell script question

I am using ksh. There is a report having amounts in the following format, 34343.67- 2343.45 23434.89- I want to sum up all the amounts. For this I first need to find out if there is a minus sign at the end and prefix it before summing up. How to achieve this? I thought of using an... (2 Replies)
Discussion started by: tselvanin
2 Replies
Login or Register to Ask a Question