LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 04-29-2003, 02:20 PM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Rep: Reputation: 45
count bytes with awk


HI THERE!Do you know how can i count bytes if a file with awk?
 
Old 04-29-2003, 02:31 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I don't know about awk baut you could use "wc".
 
Old 04-29-2003, 02:36 PM   #3
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Yep, wc is the tool you want for that. It's handy for counting things. (stands for word count)

By default the output is number of lines, words, and bytes.
 
Old 04-29-2003, 03:11 PM   #4
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,133

Original Poster
Rep: Reputation: 45
nop

I must use the awk file....I have thought this...we know that every character is one byte, So the only thing that i must do is to count the characters. DO u agree?
 
Old 04-29-2003, 03:19 PM   #5
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Why must you use awk? Don't you have wc?
 
Old 04-29-2003, 05:13 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Re: nop

Quote:
Originally posted by alaios
I must use the awk file....I have thought this...we know that every character is one byte, So the only thing that i must do is to count the characters. DO u agree?
I find this aproach rather awkward :}
wc is the way to go ;)

Cheers,
Tink
 
Old 04-29-2003, 10:56 PM   #7
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
Read the awk man page, if it can be done it's in there. Normally I would be happy to help out, but without a real reason to use the wrong tool, I can't seem to find the time. ;) wc is perfect, but even Perl is a better tool to use than awk, for this.
 
Old 04-30-2003, 09:20 AM   #8
shadowbird
LQ Newbie
 
Registered: Apr 2003
Distribution: RedHat
Posts: 27

Rep: Reputation: 15
Awk program:

BEGIN {
system( "wc -c t1.awk") | getline theCount ;
}

END {
print theCount;
}


(Okay, I cheated and used "wc" from inside awk... sue me... ::grin:
 
Old 05-13-2003, 06:41 AM   #9
realos
Member
 
Registered: Jul 2002
Location: Germany
Distribution: Redhat 7.3, Debian 3.1, Knoppix 3.1, Ubuntu 6.10
Posts: 113

Rep: Reputation: 15
hi alaios:

if you needto count bytes of one file:

bash> wc -c filename | awk '(print "total bytes in file: " $1}'

if you need to count bytes used by multiple files:

bash> ls -l | awk '{x=x+$5}; END {print "total bytes in directory: " x}'

good luck and happy coding ;>
cu,

Luqman
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
synaptic bytes mercutio Linux - Software 9 02-10-2006 04:51 PM
TX bytes vs. httpd bytes ovrload Linux - Networking 3 10-12-2005 04:19 PM
How to retrieve bytes sent AzidStar Linux - Networking 5 03-01-2005 03:25 AM
AWK: print field to end, and character count? ridertech Linux - Newbie 1 05-07-2004 05:07 PM
Should posts in general count on your post count? Joey.Dale General 16 01-27-2004 01:31 AM


All times are GMT -5. The time now is 04:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration