Need simpler version of these commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need simpler version of these commands
# 1  
Old 09-24-2014
Need simpler version of these commands

Hi all,

I am trying to grep a file with the word grand and get all the fields.. Then replace multiple spaces with single space and then get 8 th field and add all these numbers . I am able to do it but with so amny commands which i feel can be done in a simpler way

Please let me know if there is a simpler way

Code:
cat File1.$$|grep Grand > temp.txt
sed 's/ */,/g' temp.txt > temp1.txt
cut -d, -f8 temp3.txt >temp4.txt
cat temp4.txt
awk '{x+=$0}END{print x}' temp4.txt> temp5.txt


Last edited by vbe; 09-24-2014 at 05:34 AM.. Reason: code between code tags hehe but correct button...
# 2  
Old 09-24-2014
Hello Hypesslearner,

Kindly use code tags while posting your codes and commands. We can help you more, if you can please provide us the input and expected output for same.

Thanks,
R. Singh
# 3  
Old 09-24-2014
Try this:

Code:
awk '/Grand/{n+=$8;gsub(/ +/," ");print};END{print "TOTAL: "n+0}' File1.$$

This User Gave Thanks to pilnet101 For This Post:
# 4  
Old 09-24-2014
You don't specify how many (if any) of the tempN.txt files you need to keep.

I'm assuming you only want to keep temp5.txt (containing the grand total).

Code:
awk '/Grand/{$0=$8;n+=$0} 1; END{print n > "temp5.txt"}' File1.$$

# 5  
Old 09-25-2014
If you want only the temp5.txt file,
Code:
awk '/Grand/ {sum += $8} END {print sum}' File1.$$ > temp5.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need commands to fetch Guest VM OS version from Xen and KVM

Im looking for the commands that can be executed to fetch the OS Version of the VMs running on the below Hypervisors. Xen (Not the citrix Xen server, but the Xen Sever hosted on a ubuntu Machine) KVM (0 Replies)
Discussion started by: ranvirsingh
0 Replies

2. Shell Programming and Scripting

Need simpler way to find all my disk space utilization using df -h

Hi All, I am using SSH Tectia terminal to get the disk space utilization of a particular folder /opt/logs in all the servers one by one using the command df -h and looking through the list of folders manually to get /opt/logs folder disk space used percentage . The problem here is , it... (2 Replies)
Discussion started by: aakhan2011
2 Replies

3. UNIX for Dummies Questions & Answers

Simpler next month year program

I have created this program to get the next month and year. Is there a simpler way. #!/bin/ksh string=`cat Date.txt` year=`echo $string | cut -c 1-4` month=`echo $string | cut -c 5-6` echo $year$month mon=`expr $month + 1` if ; then mon=0$mon echo $mon fi if ; then month=01 ... (2 Replies)
Discussion started by: w020637
2 Replies

4. Shell Programming and Scripting

A simpler way to do this (save a list of files based on part of their name)

Hello, I have a script that checks every file with a specific extension in a specific directory. The file names contain some numerical output and I am recording the file names with the best n outcomes. The script finds all files in the directory with the extension .out.txt and uses awk to... (12 Replies)
Discussion started by: LMHmedchem
12 Replies

5. What is on Your Mind?

A simpler XML tool

We've been getting a lot of XML questions lately, and I suspect it's only going to get worse better ... Normal shell utilities just can't handle it and the "proper" solutions, do-everything perl modules or things like xmlstarlet, just make my head ache. Started coding something tonight. What... (10 Replies)
Discussion started by: Corona688
10 Replies

6. Shell Programming and Scripting

Is there a simpler way to validate user input for float?

I'm trying to only read price (FLOAT (i.e 1.10, 3.14, etc etc)) If the input is just an integer, I will add a .00 behind. (i.e 3 becomes 3.00 , 20 becomes 20.00) If the input is without 2 decimal places, I'll add a 0. (i.e 3.1 becomes 3.10) I tried using the below code, it works but I don't... (6 Replies)
Discussion started by: andylbh
6 Replies

7. Programming

How to simplify this perl script to a cleaner simpler look?

my $branch_email_e = $FORM{r_Branch}; my $hostbranch_email_e = $FORM{r_Host_Branch}; my $branch_email_f = $FORM{r_Direction_generale}; my $hostbranch_email_f = $FORM{r_Direction_generale_daccueil}; my $branch_realname_e = ''; my $branch_realname_f = ''; ... (4 Replies)
Discussion started by: callyvan
4 Replies

8. Shell Programming and Scripting

Is there a simpler way to achieve this?

Hi all I have the following which is part of a larger interactive script for adding virtual hosts to Apache's configuration (it was built for non-technical administrators). I'm curious as to whether there is a simpler way of achieving the same thing. All it does is look into the... (3 Replies)
Discussion started by: mlott
3 Replies
Login or Register to Ask a Question