The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux Shell Question: how to print the shell script name ? meili100 UNIX for Dummies Questions & Answers 3 07-01-2008 01:55 PM
Shell script question jbou1087 Shell Programming and Scripting 2 05-06-2008 02:01 AM
shell script question tselvanin Shell Programming and Scripting 2 08-28-2007 09:53 PM
Simply shell script question frustrated1 Shell Programming and Scripting 8 07-03-2005 02:22 AM
BASH shell script question ewarmour Shell Programming and Scripting 3 05-24-2002 05:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-24-2005
surjyap surjyap is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 40
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 (permalink)  
Old 11-24-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 11-24-2005
Abhishek Ghose Abhishek Ghose is offline
Registered User
  
 

Join Date: Sep 2005
Location: Chennai
Posts: 81
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0