Simply shell script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simply shell script question
# 8  
Old 07-02-2005
The simplest way is to do the whole thing in awk.

Code:
$ cat file.txt
1676
18060
10004
996
1836
16136
1712
176
10220
78908
$

Code:
sum=$(awk 'BEGIN { sum = 0 } { sum += $1 } END { print sum }' file.txt)

or more simply
Code:
sum=$(awk '{ sum += $1 } END { print sum }' file.txt)

# 9  
Old 07-03-2005
Quote:
Originally Posted by vgersh99
why not - just code everything in Bourne [#!/bin/sh]
I usually do actually! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

I am not sure which is the better way for the below shell script. I need to find the below process running and sent it to the desired user. please let me know which is most feasible right way. ps -ef | grep "Server" > /shome/kk/text.txt cat /shome/kk/text.txt| mail -s "Email... (5 Replies)
Discussion started by: ramkumar15
5 Replies

2. Shell Programming and Scripting

Shell script question

I am getting error files missing. can anyone tell me I can able to read the file. Can you tell what the other part does? xargs -i test -f {} cat $S.file | uniq | xargs -i test -f {} || error_func "files(s) missing!" (4 Replies)
Discussion started by: ramkumar15
4 Replies

3. Shell Programming and Scripting

Shell script question

daily few files will be available in one directories /azure/file and it should be moved to other directories /azure/file/recent directories if I run my script. azure/files> ll *7847* N7847.TXTFILE N7847.DMNFILE Once the script is triggered the above file should be moved to the... (3 Replies)
Discussion started by: ramkumar15
3 Replies

4. Shell Programming and Scripting

Simply question about capturing output to /dev/tty

Suppose another person wrote the following one-line shell script: echo $RANDOM > /dev/tty QUESTION #1: How can the random number, which is output to the terminal by this script, be captured in a variable? QUESTION #2: How can this be done in a cron job? Specific code, whether in ksh or... (1 Reply)
Discussion started by: Paul R
1 Replies

5. Homework & Coursework Questions

question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?! echo "enter a number " read n i=0 first=0 second=1 result=0 prime="true" echo –n " $first $second " while do result=`expr $first + $second` first=$second... (10 Replies)
Discussion started by: moonlips
10 Replies

6. Programming

question on shell script

when i run a shell script i have to type ./my_prog and the first line of my_prog has to have #!/usr/bin/env bash how do i change it to i only have to type my_prog to run it? (4 Replies)
Discussion started by: omega666
4 Replies

7. Shell Programming and Scripting

Shell script question

HI, i would like to ask you several question regarding a shell ( #!/bin/sh) i need to make a program that able to do : 1.Accept the name of a logle as the sole command line argument 2.search the specied logle for lines that have been added since the previous search. 3. construct an e-mail... (1 Reply)
Discussion started by: grandios
1 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

shell script question

I am using ksh. There is a report having amounts in the following format, 34343.67- 2343.45 23434.89- I want to sum up all the amounts. For this I first need to find out if there is a minus sign at the end and prefix it before summing up. How to achieve this? I thought of using an... (2 Replies)
Discussion started by: tselvanin
2 Replies

10. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: surjyap
2 Replies
Login or Register to Ask a Question