Korn shell script required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn shell script required
# 1  
Old 02-25-2013
Code Korn shell script required

Want a Korn shell script which reads the records in a file and at a specific position it is to be checked whether tht is blank.
eg-

Code:
dhgadjhkwdkwyuywu< blank spaces for 8 chrs >gdwyduyweeduy
xvgjdwtdjtwktdtwtdt< blank spaces for 8 chrs >udedeiueduuedu

suppose tht one line in file is of 100 characters nd position 20-28 have to be checked for blank or empty string.

Please help...
using awk will be preferred

Last edited by Scrutinizer; 02-25-2013 at 08:49 AM.. Reason: code tags
# 2  
Old 02-25-2013
Hi, what have you tried so far? Are you looking for an awk or a Kornshell solution...
# 3  
Old 02-25-2013
kornshell using awk will be fine
i have tried

---------- Post updated at 07:55 AM ---------- Previous update was at 07:54 AM ----------

Code:
#!/bin/sh
i=1
cat file1 | while read line
do
str1=`echo $line | cut -c5-10 `
if [ -z "$str1" ]
then
echo "Line No. $i -- No String in position 5-10 "
else
echo "Line No. $i -- String in position 5-10 : $str1"
fi
i=`expr $i + 1`
done

~
~

---------- Post updated at 07:56 AM ---------- Previous update was at 07:55 AM ----------

but this does not work correctly if the file is like the format I have mentioned above

Last edited by Scrutinizer; 02-25-2013 at 09:00 AM.. Reason: code tags
# 4  
Old 02-25-2013
Using awk program with substr function:
Code:
awk '
substr($0, 5, 5) ~ /^[ \t]+$/ {
        print "Line No. " NR "-- No String in position 5-10 "
}

substr($0, 5, 5) !~ /^[ \t]+$/ {
        print "Line No. " NR " -- String in position 5-10 : " substr($0, 5, 5)
} ' file

# 5  
Old 02-25-2013
Wat if the file is '|' (pipe) delimited and 5th field is to be checked for empty string and if it is found to be empty the whole data is to be pushed to another file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need urgent help with korn shell script

Hi All, Need urgent help with korn shell script, which monitors AIX WPARs Status. Basically WPARs run on a LPAR, So there is a Command "lswpar" which displays WPARs status. This script should be checking the WPARs Status and email support if WPAR is down or broken. General lswpar output is as... (3 Replies)
Discussion started by: aix_admin_007
3 Replies

2. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

3. AIX

weird korn shell script

here is the one of the scripts: script1.kshfunction haha { print "calling haha" exit } script2.ksh. script1.ksh haha | tee -a /dev/null print "i am script 2" after launching the script2, the result: --------------------------------------------- calling haha i am script 2 ... (6 Replies)
Discussion started by: getter
6 Replies

4. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

5. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Wrapper script

Hi Guys, I am trying write a wrapper script but I don't have any idea. I have 4 different korn shell scripts and all of them needs some parameters from command line (positional parameter). My script cant be interactive because its supposed to be automated. I am confused how can I write a wrapper... (6 Replies)
Discussion started by: pareshan
6 Replies

7. Shell Programming and Scripting

Korn Shell Script help required during execution...

Hi, The following Korne Shell script does not give any syntax errors but the following while running. Request you to please let me know, how can I define the variables viz.:- listDbs and getkey here, inorder to remove the error. 1) $ ksh -n setAlias $ 2) $ ksh -x setAlias +... (1 Reply)
Discussion started by: marconi
1 Replies

8. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

9. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question