learning how to script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers learning how to script
# 1  
Old 05-23-2007
learning how to script

I have this command line entry that I would like to turn into a script. I want to be able to just run the script with options for the report name and switch. Can anyone help me get started? I am hoping that by creating this script it will help me be able to create more.
I have never written one. I have read a few websites but can't find a really good one yet so if you know of any taht'd be great too.

Here is the command:
cat report.20060222 |grep Detroit | nawk -F"," '{tmp+=$10} END {print tmp}'

I want to just call the script total_rawfile.ksh

Then be able to run: total_rawfile.ksh report.20060222 Detroit


Thank you in advance for any help!
# 2  
Old 05-23-2007
total_rawfile.ksh
Code:
cat $1|grep $2 | nawk -F"," '{tmp+=$10} END {print tmp}'

# 3  
Old 05-23-2007
what did I do wrong?
I get this error:
ksh: total_rawfile.ksh: cannot execute
# 4  
Old 05-23-2007
Is the script executable?

chmod +x total_rawfile
# 5  
Old 05-24-2007
hello

i am newer.
# 6  
Old 05-24-2007
I am so dumb!
Ok now it works.

How can I put a line so that if someone types the script name it gives it it's usage. I tried this but it didnt' work:


function USAGE
{
echo "\nUSAGE: total_rawfile.ksh <report name> <switch short ID> \n"
echo "Here is an example:\n"
echo "total_rawfile.ksh RA_FW_SL4_rawfile_report.20070520.chk_SCOUT_ARCHIVE ANAJAL\n"
}

cat $1 | grep $2 | nawk -F"," '{tmp+=$10} END {print tmp}'
#grep $2
#nawk -F"," '{tmp+=$10} END {print tmp}'


Also let's say the variable has a / so like $1 is reports/daily is there anything special needed because the variable has a / in it?

thanks for the replies. And patience!
# 7  
Old 05-30-2007
anyone?? I still dont know how to put usage?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Learning to Script in Linux

Hello, I'm trying to branch out and learn Linux, but my comfort zone is PowerShell. I figure the best way to learn it is to do it so I moved my Plex Media Server to Ubuntu Server. What I'm trying to do is build a script that searches a directory and all subdirectories for files with the .ts... (5 Replies)
Discussion started by: Rhysers
5 Replies

2. Programming

Learning python, lost with script

Hi there, im just having a hard time understanding why this code does not print anything that is suppose to print: score = raw_input ('what is your score? \n') try: if 1.0 == float(score) >= 0.9: print "A" elif 0.9 > float(score) >= 0.8: ... (1 Reply)
Discussion started by: la2015
1 Replies

3. UNIX Desktop Questions & Answers

Unix shell script learning

I am trying to learn Shell scripting in UNIX. Could Any one please suggest on how to get UNIX account or any other free stimulator available for download on which I can practice Unix shell script? Thanks, sam70 (9 Replies)
Discussion started by: sam70
9 Replies

4. Shell Programming and Scripting

Learning foreach

im newbie at shell scripting. why do the following code #!/bin/tcsh setenv CBC ~/cbc/models/ foreach mix (p00p00 p02p00 p02p04) echo $mix cp $CBC/*$mix*Gyr*fits $mix/ end print(copy) only the first mix? % ./copyfromcbc.sh p00p00 wasn't it supposed to run through all words... (0 Replies)
Discussion started by: prtc
0 Replies

5. UNIX for Dummies Questions & Answers

Learning Tips - UNIX Shell Script

Can any one please provide a fast learning tips to learn UNIX shell scripting? Thanks, Gov (3 Replies)
Discussion started by: Govindh.v
3 Replies

6. UNIX for Dummies Questions & Answers

Script Language Parser for Learning

I'm new to the UNIX world and have to learn scripting for my job. Presented with multiple scripts to learn (and then have to maintain in the future) is there a utility or process to input a script in it's native form and output what each line would look like fully parsed (i.e.: all variable names... (3 Replies)
Discussion started by: kcampb9
3 Replies

7. Shell Programming and Scripting

learning how to use shell script

hello everyone, i am still trying to get this script to work, but with no luck. It is a little beyond my knowledge of scripting at the moment. The beginner book i have has an exercise listed that asks me to write a script tha allows for user input. For example " what is your name: " and then you... (3 Replies)
Discussion started by: bebop1111116
3 Replies

8. UNIX for Dummies Questions & Answers

learning on my own

can i do this? i am learning this on my own..and from the book..simple unix i am not sure if the syntax would work if statement then statement do or for or while statement done else statement fi.... I dont know how else to explain that...I hope I... (2 Replies)
Discussion started by: jonas27
2 Replies

9. UNIX for Dummies Questions & Answers

Learning to script...want a project to work on (making a small MUD)

Will it be possible to make a MUD using unix script(bash)? I know I can easilly make a "dungeon" with different rooms I can run through and such(kinda like a maze game) . What I did was made a differnt shell script for each room and used CASE for the different places to go, ex. when you press N for... (2 Replies)
Discussion started by: learningtoscrip
2 Replies
Login or Register to Ask a Question