0

I created a script ./abc.

I want to break the ouput into new lines.

mycode:

#!/bin/bash
dir="$1"

echo -n "size of file:"
du -hba $dir | sort -n -r | tail -1

my output is:

size of files: 20kb /path/to/sport

I want the output as:

size of files: 20kb
         /path/to/sport
2
  • 1
    Please would you show the part of the code that generates this. Commented May 6, 2015 at 14:02
  • @roaima I edited my question. could you please check my code. Commented May 6, 2015 at 14:29

2 Answers 2

1

I would consider something like this:

du="$(du -hba "$dir" | sort -n -r | tail -1)"
printf "size of file: %s\n\t%s\n" "${du/$'\t'*}" "${du#*$'\t'}"

The du variable takes the result of your search. It is then split into two tab-separated parts for the printf statement, with each of the parts interpolated into the format string with %s.

This construct should handle filenames containing newlines, tabs, and other unusual characters.

0
./abc | sed 's/files: /files: \n/'

I tried on my system with echo command:

$ echo "size of files: 20kb /path/to/sport" | sed 's/files: /files: \n\t/'
size of files:
        20kb /path/to/sport
1
  • could you please check my expected output once. It has to be display as : size of files: 20kb Commented May 6, 2015 at 14:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.