I am am one of these people that it isn't good enough just to say, "Here, try this...". it is important for me to understand how and why something works (or doesn't work.)
All that being said, I am trying to parse out a command that we use that was handed down to me by someone I can no longer ask questions from, and I **think** I have most of it, but not quite.
The output of this routine prints a list of amount of space used by each subdirectory, sorted by size, low to high.
The command/routine looks like so:
(and it works like a charm, btw)
From what I can muddle out, this routine:
1. Runs the "du -h" command
2. Pipes the results into a subroutine executed by perl
3. Splits each line of the output into two pieces of data each (size and subdirectory) and puts that into a hash
3. Does some kind of math on the size of each element in the hash (the "**" throws me off, and I can't locate info on what that means)
4. And prints the result with subdirectory, sorted by size, ascending
3. Does some kind of math on the size of each element in the hash (the "**" throws me off, and I can't locate info on what that means)
The ** is an exponential. 2 ** 10 is 2 to the 10th power, or 1024.
It's looking up the values of K, M, and G in the hash and getting 10, 20, 30 to calculate the sizes of 2^10, 2^20, and 2^30 for kilobytes, megabytes, and gigabytes respectively. Each line gets pushed into an array, and finally, the giant array is sorted, and printed.
Quote:
Do I have this even close to being right?
Pretty close -- but I have no idea why they made it so hard on themselves. If you don't want to bother translating K/M/G values, don't ask for them in the first place.
I see that sort of thing a lot. People will script ls -l all the time, then use a three-deep pipe chain to strip out everything but the filename... emulating plain ls with no flags.
I like having the K/M/G displayed. Makes it pretty tidy.
I can see that, but why sort after? It means doing convert, un-convert, sort, re-convert. Why not sort the machine-readable, and print the human-readable?
It divides by 1024 until it's either less than 1024, or big enough it's run out of letters. It picks space, K, M, or G depending on the number of times it divided.
Hi Friends,
I have data like below
t064266
I want output into this format
t064266
Data are space delimited and i want parse third column data.
Thanks (9 Replies)
Hi Felas
I am running Fedora and have this issue on my system:
I have the following users:
jane:x:552:100::/usr1/users/jane:/bin/bash
jules:x:553:100::/usr1/users/jules:/bin/bash
I have the following group which all users belong to:
lab:x:100:root,jules,jane
I have the... (4 Replies)
I have a script that I am writing to parse the output of information from a command.
Here is one of the lines of the output exported into the variable OUTPUT:
export OUTPUT=”name_of_system,0,5,9,55,ip_address,another_value,/PATH/OF/A/VALUE/I/NEED"
I can get the output I need... (5 Replies)
Hi all
I have written a simple perl script that has different options i.e. myscript -l -p etc
i have it so when it runs without any switches it runs a subroutine called nvrm_norm
i want to be able to do a -p option and run
pall -w -f and then called the subruotine
pall is... (1 Reply)
I've a problem parsing a string as a command:
Consider script stefano.sh as following:
#!/usr/bin/sh
txtshell="./parser.sh /ews/MyEventHandler/data/handler/StopAndMail.php eventid=StopAndMail.MVIN.6300 lot_number=1122FXB facility=EWSF3 'mailto=prova.prova@nohost.com, prova.test@nohost.com'... (2 Replies)
Lucky me, someone has installed a server and got it running with the best intentions, but leaving me a headache. :wall:
We have a simple p520 with 4 disks. 2x145Gb & 2x300Gb. The smaller disk pair have been built into a VIO mirrored rootvg, and quite right too.
The other two disks form a... (3 Replies)
What I am trying to do is write a script that makes some commands easier, now one of the commands is to rebuild mail boxes in plesk, which would would be something like
/usr/loca/psa/websrvmng --vhost-reconfigure --vhost-name=domain.com
but the domain.com bit is going to need to change with... (3 Replies)
Sorry for the duplicate thread this one is similar to the one in
https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121
Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Hi
I am trying to get to know a script I have inherited. The original author is no longer available.
Does anyone know if there is a utility to parse a ksh script and generate a report/output which details all the defined functions and their arguments? Maybe even provide a 'call trace' of how the... (1 Reply)
I have inherited admin duties on an old server running SCO Open Server 5. No changes have been made to this thing for a very long time. The server has started randomly disconnecting itself from the network. I have to reboot the server to get it to find the network again. It happens about once a... (3 Replies)