Read string from a file,plz help me to check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read string from a file,plz help me to check
# 1  
Old 05-11-2007
Question Read string from a file,plz help me to check

Code:
#!/usr/bin/ksh
exec 0<property
while read newReceiveDir
do
  if [ {$newReceiveDir:0:11} = New receive ]
  then
    sed -e 's//home/joshua/bodi/data/receive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh 
  elif [ {$newReceiveDir:0:8} = New temp ]
  then
    sed -e 's//home/joshua/bodi/data/temp/{$newReceiveDir:22}/g/' mp_validate.sh >| mp_validate.sh 
  elif [ {$newReceiveDir:0:11} = New working ]
  then
    sed -e 's//home/joshua/bodi/data/working/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh 
  elif [ {$newReceiveDir:0:11} = New archive ]
    sed -e 's//home/joshua/bodi/data/archive/{$newReceiveDir:25}/g/' mp_validate.sh >| mp_validate.sh 
  fi
done

Something wrong i the above code?

Thank you .

Last edited by Scott; 02-19-2010 at 08:54 PM.. Reason: Retro fitting Code Tags
# 2  
Old 05-11-2007
This code is KSH93 specific and contains many errors.
Code:
#!/usr/bin/ksh
exec 0<property
while read newReceiveDir
do
   if [ "${newReceiveDir:0:11}" = "New receive" ]
   then
      sed -e "s§/home/joshua/bodi/data/receive§${newReceiveDir:25}§g" mp_validate.sh >| mp_validate.tmp 
   elif [ "${newReceiveDir:0:8}" = "New temp" ]
   then
      sed -e "s§/home/joshua/bodi/data/temp§${newReceiveDir:22}§g" mp_validate.sh >| mp_validate.tmp 
   elif [ "${newReceiveDir:0:11}" = "New working" ]
   then
      sed -e "s§/home/joshua/bodi/data/working§${newReceiveDir:25}§g" mp_validate.sh >| mp_validate.tmp 
   elif [ "${newReceiveDir:0:11}" = "New archive" ]
   then # added
      sed -e "s§/home/joshua/bodi/data/archive§${newReceiveDir:25}§g" mp_validate.sh >| mp_validate.tmp 
   fi
   mv mp_validate.tmp mp_validate.sh
done

You can avoid using nested if :
Code:
#!/usr/bin/ksh
exec 0<property
while read newReceiveDir
do
   case "${newReceiveDir}" in
      New\ receive*)
         sed -e "s§/home/joshua/bodi/data/receive§${newReceiveDir:25}§g" mp_validate.sh >| mp_validate.tmp ;;
      New\ temp*)
         sed -e "s§/home/joshua/bodi/data/temp§${newReceiveDir:22}§g" mp_validate.sh >| mp_validate.tmp ;;
      New\ working*)
         sed -e "s§/home/joshua/bodi/data/working§${newReceiveDir:25}§g" mp_validate.sh >| mp_validate.tmp  ;;
      New\ archive*)
         sed -e "s§/home/joshua/bodi/data/archive§${newReceiveDir:25}§g" mp_validate.sh >| mp_validate.tmp  ;;
   esac
   mv mp_validate.tmp mp_validate.sh
done

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to count matched string then check again from last read position

Hi all, I am currently trying to figure out how can i capture a particular string from a log file, then search again but from the last line it read before onward. Basically let's say that the check runs every 5 mins via cron, counting the number of matched strings "Cannot assign requested... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

How to read file, and replace certain string with another string?

Hi all, the value in the following file is just an example. It could be a different value/network addresses. Here is my example of initial output in a file name net.txt Initial Output, net.txt The goal is to produce the following format which is to convert from CIDR to Netmask... (6 Replies)
Discussion started by: type8code0
6 Replies

3. UNIX for Dummies Questions & Answers

I need a Script to read Log string and check date at the same time

I need to check 1 log file, which is logging: 2014-08-18T09:10:39+02:00 user: XXXXX START FEATURE 2014-08-18T09:10:39+02:00 user: XXXXX FINISH FEATURE I first need to check that the START FEATURE starts and finish on the same time/date for the same user, which is different each time START... (2 Replies)
Discussion started by: TheBest43
2 Replies

4. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

5. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

6. Shell Programming and Scripting

Read File and check records for length

I need a script that will run in unix to: 1) Read and input file with 1 column that contains for ex: 0123456789 1234567890 ...etc 2) Checks the first column if it is: a. Numeric from 0 - 9 b. if it is not less... (4 Replies)
Discussion started by: mrn6430
4 Replies

7. UNIX for Advanced & Expert Users

Using FTP to check whether file is completely FTP... plz find the description below

Hi, We have some clients who will place huge files in to one of the remote server. And the shell script written in our local server to retrieve client files (using FTP) placed on one of the remote server of ours by clients. My question Is there any FTP command/script to check from my local... (1 Reply)
Discussion started by: nmsrao
1 Replies

8. Shell Programming and Scripting

Read last line of file to check for value

Folks How best to read the last line of a file, to check for a particular value? This is the last line of my file...... 00000870000002000008 0000000020000 ......I need to check that this line contains '70' in positions 7 and 8, before I continue processing. Regards ... Dave (12 Replies)
Discussion started by: daveaasmith
12 Replies

9. Shell Programming and Scripting

read string, check string length and cut

Hello All, Plz help me with: I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question