Sponsored Content
Top Forums UNIX for Advanced & Expert Users Urgent Awk manipulation query help Post 302084846 by rahul26 on Monday 14th of August 2006 04:50:06 AM
Old 08-14-2006
Quote:
Originally Posted by shereenmotor
Are you sure this is not homework?

Maybe it can be done very easily with awk, but I'm not a power user of awk, you can give this a try:
Code:
#! /bin/ksh
nol=`wc -l demo.lst | awk '{print $1}'`
count=1
while read a x y z
do
        if [[ $count -lt $nol ]]; then
                tot_x="$tot_x+$x"
                tot_y="$tot_y+$y"
                tot_z="$tot_z+$z"
                let count=$count+1
        else
                break
        fi
done < demo.lst
tot_x=`echo $tot_x | sed 's/^+//'`
tot_y=`echo $tot_y | sed 's/^+//'`
tot_z=`echo $tot_z | sed 's/^+//'`
line=`tail -1 demo.lst`
ftot_x=`echo $line | awk '{print $2}'`
ftot_y=`echo $line | awk '{print $3}'`
ftot_z=`echo $line | awk '{print $4}'`
echo "Final_Total $ftot_x-($tot_x) $ftot_y-($tot_y) $ftot_z-($tot_z)" >> spoolfile

Regards,
Tayyab
Hi ,
Brialliant.........actually i was not knowing the use of READ and was looking for something similar.
newaz Thanks A Lot....It solved my purpose....

And its not homework stuff..........a real life requirement.


Regards,
Rahul26
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk manipulation

Hi , what a wonderful command but so hard to maintain ! i have a file like that : 03/07/2006 05:58:45 03/07/2006 06:58:45 03/07/2006 07:58:50 03/07/2006 08:58:50 and i want to read it and keep only the lines with 3rd field less than 07:00:00 writing it in a second file ! ... (2 Replies)
Discussion started by: Nicol
2 Replies

2. Shell Programming and Scripting

File manipulation with awk

Could you please help me to achieve the below: In a file I need to convert the multiple lines whose filed 1 and field 5 values are same into a single line but with the field 4 values comma separed as mentioned below. Fileds after 5 shall be discarded. Also here by default all other remaining... (6 Replies)
Discussion started by: dhams
6 Replies

3. Shell Programming and Scripting

how to convert the result of the select query to comma seperated data - urgent pls

how to convert the result of the select query to comma seperated data and put in a .csv file using korn shell. Pls help me as its very urgent. Thanks, Hema. (1 Reply)
Discussion started by: Hemamalini
1 Replies

4. Shell Programming and Scripting

Query regarding string Manipulation

Dear Experts, I have to write a shell script in which i get one string of numbers (e.g 1234567890) from user & i have to chage it to (2143658709). Please suggest how can i achieve the same. Rule is: In case the number of digits is even then translation should be: 123456 -> 214365 ... (3 Replies)
Discussion started by: dhiraj4mann
3 Replies

5. Shell Programming and Scripting

$0 manipulation in awk

OK, so if $0 represent the entire record... can I change $2 and will that be reflected back in $0? I think the following answers that YES, it does work. But is there anything I should be thinking about prior to doing this? What I am actually doing is part of 5 pages of scripting and awk... (1 Reply)
Discussion started by: joeyg
1 Replies

6. Programming

urgent help with file manipulation program

Hey, i am trying to write a program that takes multiple files as command line arguments, then outputs them to a single file. i also need the option to read them back out again. essentially what i am trying to create is an archiver, however, a very simple one. The program i have accomplished so far... (1 Reply)
Discussion started by: wezzyb
1 Replies

7. Shell Programming and Scripting

Very Urgent Query... PLease help me

Dear All, I need an output file in a way as described below the above data should be static i.e. will remain the same and the second feild will print a value comming from another script as per time (please note script will be scheduled for 30 min interval in crontab, so it will run at... (1 Reply)
Discussion started by: jojo123
1 Replies

8. Shell Programming and Scripting

awk manipulation

Hallo Family, I have csv file which has over a million records in it. All i want to do is to change field 2 to have the same value as field 10. sample file:Now 0860093239,Anonymous,unconditional,+27381230283,Anonymous,unconditional,y,public,,2965511477:0A Desired output: ... (2 Replies)
Discussion started by: kekanap
2 Replies

9. Shell Programming and Scripting

awk manipulation

hello I have example file AA 11 BB 22 CC 33 And what I expect to have -a AA=11 -a BB=22 -a CC=33 can anyone help how I have this using awk? (1 Reply)
Discussion started by: vikus
1 Replies

10. Shell Programming and Scripting

awk manipulation

Hello all, Can someone help me with write part of code in awk to merge 2 files? Go through file1 check if number from column 3 exist in file2(column 2) if yes take value from column 1 and add to column 4 in file1. If value in column 4 exist in file1 skip it. file1... (2 Replies)
Discussion started by: vikus
2 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 03:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy