04-23-2008
sum(col)
I have an file a.sh which has
USSR|10|20|Asia
Canada|20|30|North America
China|30|40|Asia
I tried with era code, but is is giving wrong output
`awk -F '|' '{ area+=$2; total+=$3; }
END { print "area: " area; print "total: " total }'` /path/a.sh
awk: syntax error near line 1
awk: bailing out near line 1
/path/a.sh: USSR: not found
/path/a.sh: 10: not found
/path/a.sh: 20: not found
/path/a.sh: Asia: not found
/path/a.sh[2]: Canada: not found
/path/a.sh[2]: 30: not found
/path/a.sh[2]: 20: not found
/path/a.sh[2]: North: not found
/path/a.sh[3]: China: not found
/path/a.sh[3]: 40: not found
/path/a.sh[3]: 30: not found
/path/a.sh[3]: Asia: not found
echo $area
40
echo $total
150
It gave the following output. It is supposed to give the output as 60 and 90It has some error also. Pl help me
Thanks
Babu
10 More Discussions You Might Find Interesting
1. Ubuntu
Hello,
I have a 1.6 GB file that I would like to modify by matching some ids in col1 with the ids in col 1 of file2.txt and save the results into a 3rd file.
For example:
File 1 has 1411 rows, I ignore how many columns it has (thousands)
File 2 has 311 rows, 1 column
Would like to... (7 Replies)
Discussion started by: sogi
7 Replies
2. Shell Programming and Scripting
Hi,
I have two different files, one has two columns and other has only one column. I would like to compare the first column in the first file with the data in the second file and write a third file with the data that is not present is not common to them.
First file:... (26 Replies)
Discussion started by: swame_sp
26 Replies
3. Shell Programming and Scripting
cat *.out |grep "<some text>" | awk '{print $6}'
For ex,This will reutrn me
11111
22222
is it possible to add these two numbers in the above given command itself?I can write this to a file and find the sum.
But I prefer to this calculation in the above given line itself.
Any... (3 Replies)
Discussion started by: prasperl
3 Replies
4. Shell Programming and Scripting
Hello friends,
I have a database export and with this export i need to find some statistics which is required. I take the export of a table with only 3 columns like this:
2nd 3rd 12th
123 05.11.2010 09:27 0
124 05.11.2010 09:28 0
125 05.11.2010 09:34 1
126 05.11.2010 09:39 0... (5 Replies)
Discussion started by: EAGL€
5 Replies
5. Shell Programming and Scripting
Hi, Experts,
I have a requirement as following:
my source file:
a
a
a
b
b
c
c
c
c
I need add one more colume as following:
1 a
2 a
3 a
1 b
2 b
1 c
2 c (4 Replies)
Discussion started by: ken002
4 Replies
6. UNIX for Advanced & Expert Users
Hello everyone,
I am writing a script to process data from the ATP world tour.
I have a file which contains:
t=540 y=2011 r=1 p=N409
t=540 y=2011 r=2 p=N409
t=540 y=2011 r=3 p=N409
t=540 y=2011 r=4 p=N409
t=520 y=2011 r=1 p=N409
t=520 y=2011 r=2 p=N409
t=520 y=2011 r=3 p=N409
The... (4 Replies)
Discussion started by: imahmoud
4 Replies
7. Shell Programming and Scripting
Hello,
I have some tab delimited data and I need to move the last col. I could hard code it,
awk '{ print $1,$NF,$2,$3,$4,etc }' infile > outfile
but it would be nice to know the syntax to print a range cols.
I know in cut you can do,
cut -f 1,4-8,11-
to print fields 1,... (8 Replies)
Discussion started by: LMHmedchem
8 Replies
8. Shell Programming and Scripting
Hi Friends,
This is the only solution to my task. So, any help is highly appreciated.
I have a file
cat input1.bed
chr1 100 200 abc
chr1 120 300 def
chr1 145 226 ghi
chr2 567 600 unix
Now, I have another file by name
input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies
9. Shell Programming and Scripting
Hi,
Please help with this.
I have several excel files (with and .xlsx format) with 10-15 columns each.
They all have the same type of data but the columns are not ordered in the same way.
Here is a 3 column example. What I want to do add the alphabet
from column 2 to column 3, provided... (9 Replies)
Discussion started by: newbie83
9 Replies
10. Shell Programming and Scripting
Hi there,
I have 2 files in following format
cat file_1
Storage Group Name: aaaa
HBA UID SP Name SPPort
------- ------- ------
0 21
Storage Group Name: bbbb
HBA UID... (2 Replies)
Discussion started by: jpkumar10
2 Replies
LEARN ABOUT DEBIAN
xml::dom::xpath
XPath(3pm) User Contributed Perl Documentation XPath(3pm)
NAME
XML::DOM::XPath - Perl extension to add XPath support to XML::DOM, using XML::XPath engine
SYNOPSIS
use XML::DOM::XPath;
my $parser= XML::DOM::Parser->new();
my $doc = $parser->parsefile ("file.xml");
# print all HREF attributes of all CODEBASE elements
# compare with the XML::DOM version to see how much easier it is to use
my @nodes = $doc->findnodes( '//CODEBASE[@HREF]/@HREF');
print $_->getValue, "
" foreach (@nodes);
DESCRIPTION
XML::DOM::XPath allows you to use XML::XPath methods to query a DOM. This is often much easier than relying only on getElementsByTagName.
It lets you use all of the XML::DOM methods.
METHODS
Those methods can be applied to a whole dom object or to a node.
findnodes($path)
return a list of nodes found by $path.
findnodes_as_string($path)
return the nodes found reproduced as XML. The result is not guaranteed to be valid XML though.
findvalue($path)
return the concatenation of the text content of the result nodes
exists($path)
return true if the given path exists.
matches($path)
return true if the node matches the path.
SEE ALSO
XML::DOM
XML::XPathEngine
AUTHOR
Michel Rodriguez, mirod@cpan.org
COPYRIGHT AND LICENSE
Copyright 2003 by Michel Rodriguez
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.8.8 2008-04-14 XPath(3pm)