# Need help with output formatting

**URL:** <https://community.unix.com/t/need-help-with-output-formatting/307663>\
**Category:** Shell Programming and Scripting\
**Created:** [April 2, 2012, 2:39pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663 "2012-04-02T14:39:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick1097](https://community.unix.com/letter_avatar/nick1097/32/5_5575768a8748004e209b776fc1b2916d.png) [@Nick1097](https://community.unix.com/u/Nick1097)\
**Post date:** [April 2, 2012, 2:39pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/1 "2012-04-02T14:39:50Z")

</div>

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....

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 2, 2012, 2:47pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/2 "2012-04-02T14:47:36Z")

</div>

Just run it -- by itself.

No backticks needed.

No echo needed.

No tr needed.

---

<div class="post-metadata">

**Author:** ![Nick1097](https://community.unix.com/letter_avatar/nick1097/32/5_5575768a8748004e209b776fc1b2916d.png) [@Nick1097](https://community.unix.com/u/Nick1097)\
**Post date:** [April 2, 2012, 3:06pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/3 "2012-04-02T15:06:23Z")

</div>

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

cant it says Documents: not found

thanks for the quick reply btw

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 2, 2012, 3:09pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/4 "2012-04-02T15:09:30Z")

</div>

By 'by itself' I mean

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![Nick1097](https://community.unix.com/letter_avatar/nick1097/32/5_5575768a8748004e209b776fc1b2916d.png) [@Nick1097](https://community.unix.com/u/Nick1097)\
**Post date:** [April 2, 2012, 3:38pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/5 "2012-04-02T15:38:36Z")

</div>

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

btw got bit more problems hehe

```nohighlight
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 😛

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 2, 2012, 3:45pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/6 "2012-04-02T15:45:37Z")

</div>

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.

```nohighlight
# 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

```

---

<div class="post-metadata">

**Author:** ![Nick1097](https://community.unix.com/letter_avatar/nick1097/32/5_5575768a8748004e209b776fc1b2916d.png) [@Nick1097](https://community.unix.com/u/Nick1097)\
**Post date:** [April 3, 2012, 3:46am UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/7 "2012-04-03T03:46:45Z")

</div>

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

```nohighlight
du test | grep a

```

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

i try with

```nohighlight
ls -RFs test | grep a

```

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

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 3, 2012, 1:17pm UTC](https://community.unix.com/t/need-help-with-output-formatting/307663/8 "2012-04-03T13:17:17Z")

</div>

Why not just

```nohighlight
ls -RFs test/*a*

```
