Formatting the output of a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting the output of a script
# 1  
Old 09-15-2009
Tools Formatting the output of a script

Dear readers,

I have a script that counts the number of files in particular directories in my home location and displays the output. Now I have 13 directories in my home location. I am getting the output as :

Avishek_dir 13
Kunal_dir 17
Shantanu_dir 18
Arup_dir 12
Pranabesh_dir 19
.
.
.
etc

like this
I want the output like
Avishek_dir--------13
Kunal_dir ---------17
Shantanu_dir------18
Arup_dir-----------12
Pranabesh_dir-----19

Can you tell me how to do it Smilie.

Thanks in advance .

Regards
Avishek
# 2  
Old 09-15-2009
whats the diff...???both look same
# 3  
Old 09-15-2009
Quote:
Originally Posted by vidyadhar85
whats the diff...???both look same

I want the directory name and the output to be distributed linear fashion, like in two coloumns .
# 4  
Old 09-15-2009
Pipe the output to:

Code:
awk '{printf("%-25s%s\n",$1,$2)}'

# 5  
Old 09-15-2009
use printf to print o/p
if you know the length of the longest dir name then you can easily format it if not calculate it and format
for ex:
Code:
printf("%-20s%-3s",diname,file_count)

# 6  
Old 09-15-2009
the length of the longest directory is 17 ... where to use that length ...Smilie
# 7  
Old 09-15-2009
then as Franklin suggested pass the o/p of your script to
Code:
script_name|awk '{printf("%-25s%s\n",$1,$2)}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Script Output in Outlook Formatting Issue

When i execute the below shell script with 2 different Input files, for one of the data files (datafile1) my email message body in the outlook messes up and every thing comes up in one line. May i please know what i am doing wrong here or how to fix this? The only difference in data files is one is... (1 Reply)
Discussion started by: Ariean
1 Replies

2. Shell Programming and Scripting

SQL Query in Shell Script output formatting

Hi All, #!/bin/ksh call_sql () { sql=$1 sqlplus -s $sqlparam_sieb <<EOF SET ECHO OFF; SET NEWPAGE NONE; SET SQLBL OFF; SET VERIFY OFF; SET LINESIZE 2000; SET... (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies

3. Shell Programming and Scripting

Formatting output of script

I'm looking for a way to neaten up the out put of an ldapquery. I might get one, none, or several returns for each query; and each query consists of multiple lines. And while each return will contain the same types of info, it might be in a different order, like: uniq: 1 ip: 192.168.2.3... (3 Replies)
Discussion started by: jnojr
3 Replies

4. Shell Programming and Scripting

Formatting Shell script output to Excel

I am facing a problem formatting the output of my shell script in excel. We are directing the output of the script to an excel sheet and need long integer type data printed in Excel as it is (i.e. not in the default scientific notation). Also, leading zeroes(if any) in the output are getting... (4 Replies)
Discussion started by: bornali.p
4 Replies

5. Shell Programming and Scripting

Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys.. Need your help to format the output of my shell script. I am using spool command to take out put in csv file. below is my code. (for example) col USERNAME for a15 col EMAIL for a30 col FULL_NAME for a20 col LAST_LOGIN for a40 col DATE_CREATED for a40 SPOOL 120.csv... (3 Replies)
Discussion started by: Agupte
3 Replies

6. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: Nick1097
7 Replies

7. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

8. Shell Programming and Scripting

Formatting the query output using shell script

Hi All, I'm finding it difficult to format the query output that was returned in a shell script. Actually i have one shell script which does some DB stuff and depending on the result it will do some more tasks. My question here is to format the query output returned by mysql. Intitally my... (5 Replies)
Discussion started by: RSC1985
5 Replies

9. Shell Programming and Scripting

Formatting Sar Output script

Hi, We have 2 scripts below for reporting sar output which are pretty same. In first script i want to add to the program whatever is given in the comments. In second script I want to use while true to run this program every hour and everything that is in comment. Finally I want to club... (0 Replies)
Discussion started by: noorm
0 Replies

10. Shell Programming and Scripting

Formatting Script Output

Hello all, Can somebody please offer some advice. I'm working on a small script to list all packages on the local and remote systems and need it in the following format. Machine Name, Package, Version Here is what i have so far but i can't seem to get the output of the hostname to loop to... (3 Replies)
Discussion started by: liketheshell
3 Replies
Login or Register to Ask a Question