@# Quotes DB     useful, funny, interesting





Google
 
Web www.quotesdb.info
Undernet  |  EFnet  |  Quakenet  |  Freenode  |  Dalnet  |  Ircnet  |  Galaxynet
Page: 1 2 3



Comments:

<0> I need to extract the first two fields of master.p***wd and have done it with awk before but can't seem to remember. What I type is cat master.p***wd | awk {print $1, $2}>outputfile but that bails on me
<1> NotLarry: master.p***wd use spaces or : and word separators
<1> ?
<1> as word separator?
<1> ?
<2> Hej.
<2> gnubien: Have you notice the large number of kids coming here lately and half-asking questions?
<2> s/notice/noticed/
<1> pr3d4t0r: yea
<3> how do you
<4> hey guys, I am trying to find the largest partition based on the output of mac-fdisk /dev/blah would you guys help me with the sed command? here is the output http://keanmarine.com/cool and I have something like mac-fdisk -l /dev/hda | sed '1,6d' | sed 's/\*/ /' | sort -k 4 -g | tail -n 1 | gawk '{print $1}'
<4> but im not sure if that will produce the largest partition every time
<4> any one have any idea?
<4> thanks, i will be around if anyone catches this:)
<2> dcstimm: Which value do you care about?
<2> dcstimm: The length?



<4> well I would like it to output the biggest one any way it can
<2> dcstimm: Yeah, but which column?
<2> dcstimm: length?
<4> ( size )
<4> probably is best
<2> dcstimm: OKi.
<4> or length
<4> hopefully they turn the same results
<2> dcstimm: Let's use length, since it's a magnitude without a scale (i.e. no trailing K or M or anything).
<4> ok
<2> dcstimm: Let's say that fdisk saved this to partitions.txt, for sake of argument.
<4> ok
<5> "dcstimm" at 68.8.230.16 pasted "output of /proc/partitions" (12 lines, 303B) at http://sial.org/pbot/19292
<2> dcstimm: Hrm...
<4> maybe I can use that too
<2> dcstimm: Do you care about free space, or can we ignore it?
<4> ignore it
<2> dcstimm: Let me ask this another way: do you want to consider the "free space" partitions in your listing?
<4> no I dont
<2> dcstimm: OKi, easy then.
<4> only partitions with HFS, but sometimes HFS is lower case, so its kinda annoying
<2> awk '!/type/ { if ($4 != "@") if ($4 > lMax) { lMax = $4; partition = $1; } } END { printf("%s is largest at %d\n", partition, lMax); }'
<2> awk '!/type/ { if ($4 != "@") if ($4 > lMax) { lMax = $4; partition = $1; } } END { printf("%s is largest at %d\n", partition, lMax); }' < partitions.txt
<4> its saying Block is largest at 0
<4> but I just want it to output hda1 or hda2 or what ever
<4> it would be reading from fdisk -l /dev/hda which outputs exactly what you saw
<2> dcstimm: What command are you running on that Mac?
<4> well I am booting up a ubuntu livecd
<2> dcstimm: Ah.
<4> and running fdisk -l /dev/hda to see the output
<4> http://keanmarine.com/cool is the output of fdisk -l /dev/hda
<2> dcstimm: Let me look again.
<4> ok
<4> thanks so much
<4> I have been stumped all day
<4> it might be easier from the file http://sial.org/pbot/19292
<2> dcstimm: It's easier with the second one.
<4> ok
<4> the problem with it is that hda and hdc or anything that doesnt have a trailing number has to be ignored
<4> because the values on those are bigger
<2> dcstimm: cat partitions.txt | awk '!/major/ && !/^$/ { if ($3 > lMax) { lMax = $3; partition = $4; } } END { printf("Largest: %s - %d\n", partition, lMax); }'
<2> dcstimm: Nah.
<2> dcstimm: This works fine.
<4> hmm it didnt, because it picked hdc, which needs to be ignored
<2> dcstimm: cat partitions.txt | awk '!/major/ && !/hdc/ && !/^$/ { if ($3 > lMax) { lMax = $3; partition = $4; } } END { printf("Largest: %s - %d\n", partition, lMax); }'
<4> but hdc might be sda or sdb, it needs to always be able to find the largest based on what is plugged in
<2> dcstimm: So give me all the rules FIRST, don't change them after I gave you the program.
<4> sorry
<2> dcstimm: Based on the input you showed me, that works just fine.
<4> yeah im sorry, let me explain what is going to happen
<4> I need to get the partition that contains the data on any drive that is plugged in
<4> most times those drives will be sdb or sda or hda or something along that..
<2> dcstimm: OKi.
<4> thats why I liked fdisk -l /dev/hda because I had a script that found the drives that were plugged in
<4> and the output would always be same based on what device it was reading
<2> dcstimm: OKi, so pick one output style.
<2> dcstimm: If it's the first one, then tell me about any weird rules I ought to know.
<4> so the first one would probably be best
<2> dcstimm: OKi.
<4> and it needs to find the largest partition based on length
<2> dcstimm: awk '!/type/ && !/Block/ && !/Device/ && !/^$/ { if ($4 != "@") if ($4 > lMax) { lMax = $4; partition = $1;} } END { printf("Largest = %s - %d\n", partition, lMax); }' < partitions.txt



<4> cool
<4> that works
<4> how do I make the output just say "/dev/blah"
<2> dcstimm: In the END block, change that whole printf(...); to print(partition);
<4> perfect
<4> thank you so much
<2> dcstimm: You're welcome.
<4> hopefully the length will always be the largest partition
<2> dcstimm: The length in fdisk == number of blocks == largest partition on a given device.
<4> cool
<4> pr3d4t0r, if the output of a command was 8008371 Blocks how would you convert that to GB?
<2> dcstimm: What's the number of bytes per block?
<4> that should be around 8gb
<4> probably is 7.6G
<2> dcstimm: It looks like each block is 1024 bytes.
<4> yeah
<2> dcstimm: So you'd do: 1024*nBlocks/1073741824
<2> dcstimm: Or...
<2> dcstimm: nBlocks/1048576.
<4> so lets say cat output.txt gave me 8008371
<4> how would I get the output to say 7.6G
<2> dcstimm: ***ume that 8008371 is stored in variable nBlocks (or in lMax, in our previous example).
<2> dcstimm: printf("%7.2f\n", (lMax/1048576));
<4> hmm
<4> pr3d4t0r, kinda confused
<2> dcstimm: Now it's the time then to learn awk.
<2> dcstimm: You can probably learn the whole language in about 15 minutes.
<4> It would probably take me longer:)
<4> so to make it simple so I can follow it, if the output of cat blah.txt was 8008371 how would I set that up? so cat blah.txt | awk print((lMax/1048576))
<4> I cant figure it out
<2> dcstimm: cat blah.txt | awk '{ print($1/1048576); }'
<4> ah
<2> dcstimm: Dude, awk is dead easy.
<2> dcstimm: You can really learn it in a few minutes.
<2> dcstimm: Do you know how to code in bash?
<4> Yeah it looks it if I can get past the syntax
<4> yes
<2> dcstimm: bash is a lot harder to learn than awk.
<2> dcstimm: awk's syntax is very C-like.
<4> all these command make sense once I break them down
<4> cat /proc/partitions | awk 'NR == 10 {print $3}' | awk '{ print($1/1048576); }'
<4> I know some, and I am getting better
<4> cat /proc/partitions | awk 'NR == 10 { print($3/1048576); }'
<4> like that is better
<2> dcstimm: There you go.
<4> sweet:)
<4> thanks a bunch
<4> I feel so dumb sometimes and its awesome i have a place I can turn to for help
<4> I really thank you
<2> dcstimm: You're welcome.
<2> dcstimm: Here's a way of doing that in bash...
<2> dcstimm: Actually, never mind.
<4> heh
<2> dcstimm: That'd just mess with your head.
<4> well I guess it will work fine:)
<2> dcstimm: Cheers.
<4> thanks:)
<2> Greetings.
<6> oi
<7> Hi, how can I dump the output of AWK directly into a MySQL table?
<2> JoeBlacken: Hej.
<7> pr3d4t0r, what?
<2> JoeBlacken: You can use system() and sprintf()
<7> pr3d4t0r, do you know a website that shows that?
<2> JoeBlacken: man awk ;)
<2> JoeBlacken: What's the output like?
<2> JoeBlacken: All you have to do is wrap that output in an INSERT or UPDATE statement, then call mysql with system();.
<2> JoeBlacken: And no, I don't know of any web sites that have those infos.
<6> doesn't mysql have some app that can read sql commands from stdin?
<2> iSteve: /usr/bin/mysql
<6> it'd be more efficient
<7> pr3d4t0r, thanx
<6> then mysql_client="/usr/bin/mysql"; while (doing your sql statement) { print statement | mysql_client; } close(mysql_client);


Name:

Comments:

Please enter the result of the sum 63 + 46 (to avoid spam):






Return to #awk
or
Go to some related logs:

#perl
fedora xen windows guest
gentoo Xorg -configure caught signal 11
#bind
#physics
p4p800 irqpoll ubuntu
+freenx +no screen +debian
openc++ sucks
#web
#debian



Home  |  disclaimer  |  contact  |  submit quotes