- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- my problems with shell script..awk..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 12:53 AM
02-05-2007 12:53 AM
I have directory in which there are 20-30 files..
I would like to sumarise $12 $13 $14 fiels in each file but first line in every file needs to be excluded..
here is what I tried:
dir=/my/files
ls /path/to > f.dat
for file in $(< f.dat);
do
sed -e "1,1d" $dir/file > $dir/file.new
awk '{print $12' file.new >> sum
awk '{print $13' file.novi >> sum
awk '{print $14' file.novi >> sum
done
but this is not working as I would like...
thanks in advance..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 12:58 AM
02-05-2007 12:58 AM
SolutionYou can cause 'awk' to skip the first record instead of involving a separate filter like 'sed'.
# awk 'NR>1 {X+=$12};END{print X}' file
...would read 'file' but skip the first record and sum all of field-12 into 'X' printing its summation at the end.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 01:04 AM
02-05-2007 01:04 AM
Re: my problems with shell script..awk..
also FS is "|" I forgot to mention...
well..it is not that hard for me to do that for one file..ok it can be done with one awk or as I did for one file with sed and awk...
But what if I have multiple files..in one directory and I need to sum all $12 fields..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 01:12 AM
02-05-2007 01:12 AM
Re: my problems with shell script..awk..
"But what if I have multiple files..in one directory and I need to sum all $12 fields.."
Redirect the sum of each file into an output file (append mode), then sum that file.
James's solution can be used for this again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 01:16 AM
02-05-2007 01:16 AM
Re: my problems with shell script..awk..
i think I figured it..thanks for the clue..:)
for file in $(< f.dat);
do
awk -F "|" 'NR>1 {print $8;}' /path/$file >> loook
done
I guess that is that... ;)
cheers...and many thanks for prompt assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 01:25 AM
02-05-2007 01:25 AM
Re: my problems with shell script..awk..
With a minor tweak to JRF's solution that gives:
awk 'NR>1 {X+=$12; Y+=$12; Z+=$14};END{print X "\n" Y "\n" Z}" *
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 01:30 AM
02-05-2007 01:30 AM
Re: my problems with shell script..awk..
If you want to sum from multiple files, simply cahnge the NR to FNR. Thus instead of skipping only the first record (recorded as NR>1 you can skip the first record of each *file* by testing FNR>1.
# awk 'FNR>1 {X+=$3};END{print X}' file1 file2 file3 ...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2007 01:38 AM
02-05-2007 01:38 AM
Re: my problems with shell script..awk..
Ooops, I cut & past the wrong line.
Make that:
awk 'FNR>1 {X+=$12; Y+=$12; Z+=$14};END{print X "\n" Y "\n" Z}' *
Hein.