Need help with output formatting

Hey can anyone help me with newline formatting?
i bet someone will ask why im rewriting du code, im trying to write a simple script that have slightly different function than du lol....

echo $(du "$dval" | tr ' ' '\n')

atm with above code it will printout

i've tried sed and awk... cant understand how it works... sry im new to shell

4 Documents/Templates 4 Documents/Music 4 Documents/Pictures 4 Documents/Videos 20 Documents

how to i make the output into

4 Documents/Templates
4 Documents/Music
4 Documents/Pictures
4 Documents/Videos
20 Documents

like the normal format u will get when just use du Documents?

Just run it -- by itself.

No backticks needed.

No echo needed.

No tr needed.

by running by itself u mean by
$(du "$dval") ?

cant it says Documents: not found

thanks for the quick reply btw

By 'by itself' I mean

du Documents

Just that, only that, nothing but that.

When it says 'file not found', it almost certainly means what it says -- there's nothing named 'Documents' in the current directory for it to measure the size of.

What does the output of ls look like?

oo haha i did that and it works.. thanks alot

btw got bit more problems hehe

if [$# -ne "0"]
then for p in $@;
do (du $dval | grep "$p")
done;

that code is to get the size of specific directory i want..
is there a way i need to get total sum for each of the specified directory

there's a way to do it with du -s file1 file2
but that require me to be inside the directory that contain file1 and file2

---------- Post updated at 02:38 PM ---------- Previous update was at 02:24 PM ----------

oo nvm i found out that i can use the find function to do that lol

---------- Post updated at 02:38 PM ---------- Previous update was at 02:38 PM ----------

thanks alot for the previous help :stuck_out_tongue:

You don't need the find utility to use a folder which you already know of. All find is doing is printing out the relative path for you.

Just give du a full path or a relative path to where you want.

# Relative path, the OS will assume the path begins with '/path/to/currentfolder/'
du path/to/file
# Absolute path, starts at /
du /absolute/path/to/whatever
1 Like

lol... sometimes i wonder y i just cant see the easier way .. thanks again

---------- Post updated 04-03-12 at 02:46 AM ---------- Previous update was 04-02-12 at 02:55 PM ----------

hmm now im trying to make an alternate du function

du test | grep a

above will print out
4 test/a/b
8 test/a

i try with

ls -RFs test | grep a

it doesnt really give me the same result.. is there anyway i can achieve that?

Why not just

ls -RFs test/*a*