how to make syntax into a korn script??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to make syntax into a korn script??
# 1  
Old 11-13-2007
how to make syntax into a korn script??

ok i have this script called script.nawk:


BEGIN {print "List\n"}
BEGIN {print "AL"}
BEGIN {print "AM"}
/EAST/ {print $3, $2}
END {print "End of Report"}

How would I change this so that I don't have to type nawk -f script.nawk filename?

Instead just run it as a korn script?

thanks!
# 2  
Old 11-13-2007
$ chmod +x script.nawk
$ script.nawk myInputFile

script.awk:
Code:
#!/bin/nawk -f

BEGIN {print "List\n"}
BEGIN {print "AL"}
BEGIN {print "AM"}
/EAST/ {print $3, $2}
END {print "End of Report"}

# 3  
Old 11-13-2007
thank you for your reply.
What if i want to make it a .ksh file???

so far I have this:

#!/bin/ksh


echo "List"
echo "AL"
echo "AM"


echo "End of Report"

But I dont know how to put the /EAST/ {print $3, $2} statement to make it work.

Thanks!
# 4  
Old 11-13-2007
why bother? use the applicable tools for the job:

$ chmod +x script.ksh
$ script.ksh myInputFile

script.ksh:
Code:
#!/bin/ksh

nawk ' 
   BEGIN {print "List\n"}
   BEGIN {print "AL"}
   BEGIN {print "AM"}
  /EAST/ {print $3, $2}
  END {print "End of Report"}' "${1}"

# 5  
Old 11-13-2007
is the $1 the input file put at the command line after script name?

Also when do you know to use:

print
echo
or begin???

By the way it worked but it did not grab any data from my file???

thanks!

Last edited by llsmr777; 11-13-2007 at 05:09 PM..
# 6  
Old 11-13-2007
Quote:
Originally Posted by llsmr777
is the $1 the input file put at the command line after script name?
yes
Quote:
Originally Posted by llsmr777
Also when do you know to use:

print
echo
or begin???
depending on the context/tool that's being used
Quote:
Originally Posted by llsmr777
By the way it worked but it did not grab any data from my file???
thanks!
Either
  1. your data file is not what you think it's
  2. your awk script is wrong
Post a sample file and the desired result.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot find correct syntax to make file name uppercase letters

I have a file name : var=UsrAccChgRpt I want to make them upper case. Tried: $var | tr Error: tr: Invalid combination of options and Strings. Usage: tr | -ds | -s | -ds | -s ] String1 String2 tr { -d | -s | -d | -s } String1 Could you please help. I am using AIX... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Pass script with parameter in korn shell script

I have written a script which will take input parameter as another script. However, if the script passed as input parameter has parameters then this script doesn't work. I have a script b.ksh which has 1 and 2 as parameters I have a script c.ksh which has 3,4 and 5 as parameters vi a.ksh... (1 Reply)
Discussion started by: Vee
1 Replies

3. Shell Programming and Scripting

perl script to korn shell script

I have a perl script which replaces "*" with "|" and "~" with "\n" also it takes the file content starting with ST till record starting with SE written a differnet file, I wanted this to be convereted into KSH script, can anyone help me perl script: perl -e ' $file_counter=0;... (7 Replies)
Discussion started by: atlantis_yy
7 Replies

4. Shell Programming and Scripting

help with korn script

Hi guys, I am new to unix scripting. I have a folder rx and it has subfolders rx1,rx2 and rx3 each subfolder has 4 directories each load,land,arch and extr I have the below tar and rm commands using wich we should write a shell script rx1-- tar -cf... (2 Replies)
Discussion started by: Kornscript
2 Replies

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

6. Web Development

How to make "enter" work in HTML syntax

I have one syntax to find something from desktop on server, the script is as below, I actually speaking don't know anything in this script. It creates a window, where i get a drop down boxes with folder names given below and a blank box where i have to put the folder name to search. and then I... (2 Replies)
Discussion started by: patilrakesh1984
2 Replies

7. Shell Programming and Scripting

Running a BATCH script from my korn script with multiparameters

I've this BATCH script to run from my korn script... The command is /usr/local/BATCH/runBatch.sh PARAM1 'PARAM2 -PARAM21 PARAM22' (runBatch takes parameter 1 = PARAM1 parameter 2 = 'PARAM2 -PARAM21 PARAM22' ) If i run this command from command line it just runs fine... ... (7 Replies)
Discussion started by: prash184u
7 Replies

8. Shell Programming and Scripting

help with Korn script

Hello All.. Can someone tell me how to use "backspace" key in a script. I tried to use ^C (type from the keyboard) but its not working. I know its a silly question to ask but I am really frustated with this thing for good 1 hour or so. I am trying to provide an input file to a script so that I do... (3 Replies)
Discussion started by: solaix14
3 Replies

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

10. Shell Programming and Scripting

korn syntax

Hi, how do I write this condition in korn shell: file="*.html" if then echo "$file" fi I am trying to find all html files from a input text file that were created today and ftp them to a different server. please help. (1 Reply)
Discussion started by: sajjad02
1 Replies
Login or Register to Ask a Question