How to format output in columns by appending multi lines one by one?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to format output in columns by appending multi lines one by one?
# 1  
Old 04-25-2014
How to format output in columns by appending multi lines one by one?

Hi,
I need to display output in below format
Customer : Apr 24 16:31 Customer_Name_111121.txt
|---Space---|Apr 24 16:32 Customer_Name _111121. txt
|---Space---|Apr 24 16:34 Customer_Name_111112. txt
|---Space---|Apr 24 16:35 Customer_Name _222223. txt
|---Space---|Apr 24 16:37 Customer_Name_999999. txt
Brain-UCG : Apr 24 16:35 User_config_20140107.dat
|---Space---|Apr 24 16:36 User_config_20140110.dat
|---Space---|Apr 24 16:36 User_config_20140109.dat

I am using below command and getting Output like:-

Code:
FILE_LIST="$FILE_LIST$(printf '\t\t\t\t%-19s' " $FILE_NAME")$(printf '%-5s' ":")$(ls -ltr | grep -w "Apr 24" |  awk -F ' ' '{print $6,$7,$8,$9}')"$'\n'
 paste <(printf '  %-5s' "$FILE_LIST")

Customer : Apr 24 16:31 Customer_Name_111121.txt
Apr 24 16:32 Customer_Name _111121. txt
Apr 24 16:34 Customer_Name_111112. txt
Apr 24 16:35 Customer_Name _222223. txt
Apr 24 16:37 Customer_Name_999999. txt
Brain-UCG : Apr 24 16:35 User_config_20140107.dat
Apr 24 16:36 User_config_20140110.dat
Apr 24 16:36 User_config_20140109.dat

Customer,User are the name of files which call one by one in $FILE_NAME
Could you please let me know what I have missed to get desire output

Thanks,
kraut
# 2  
Old 04-25-2014
Please re-post the requirement with code-tags. Just like you did for the command you are using.

Regarding the requirement, its not very clear what you are looking for.
Where does the texts "Customer", "Brain-UCG" coming from? Are they predefined?
below format looks more generic to me. but that's purely upto your decision and requirement.
Code:
Customer : 
          Apr 24 16:31 Customer_Name_111121.txt
          Apr 24 16:32 Customer_Name _111121. txt
          Apr 24 16:34 Customer_Name_111112. txt
          Apr 24 16:35 Customer_Name _222223. txt
          Apr 24 16:37 Customer_Name_999999. txt
Brain-UCG : 
          Apr 24 16:35 User_config_20140107.dat
          Apr 24 16:36 User_config_20140110.dat
          Apr 24 16:36 User_config_20140109.dat

I see you just need the last four columns of ls -l output ?
# 3  
Old 04-25-2014
As clx says, where do the two head words come from? For the indentation, use
Code:
printf "%11s %4s %2s %5s %25s\n", " ", $6, $7, $8, $9

instead of plain print
# 4  
Old 04-30-2014
Hi

Thanks for help. I Have tried with suggested changes but still have not able to get the formatted output what I want.

From log files I graped file name(customer, User, Brain-UCG...) and i want the list of files that we received on particular day e.g"Apr 24" with time stamp(all file name must be display one below another)
HTML Code:
Customer :Apr 24 16:31 Customer_Name_111121.txt
          Apr 24 16:32 Customer_Name _111121. txt
          Apr 24 16:34 Customer_Name_111112. txt
          Apr 24 16:35 Customer_Name _222223. txt
          Apr 24 16:37 Customer_Name_999999. txt
Brain-UCG :Apr 24 16:35 User_config_20140107.dat
           Apr 24 16:36 User_config_20140110.dat
           Apr 24 16:36 User_config_20140109.dat
Its what exactly want to display....Please give me some clicks....
# 5  
Old 04-30-2014
Can't help if you don't give us the required info, be very specific: Where and how do you get the filenames from, and how do you transfer them to awk; how do you pass the desired date to awk?
# 6  
Old 04-30-2014
Hi AudiC,

This requirement is a part of script that I hv made. Below id detail description.
1.Date “24 Apr” is user input date for which we need to search in multiple log files and return the name of file in which error is trace on this particular date and if found then it return file name in $ FILE_NM_DISP
2. Now for file name in $ FILE_NM_DISP I have to get all the file located at particular directory I received at that day(24 Apr) and $FILE_PATH gives path where files are placed.
3.All above is achieved and only thing is to display this information in formatted manner...
4.$FILE_LIST only used for formating out put and print list of files.i can chage it any manner to get formatted output.
Code I am using for :-
Code:
cd $HOME"$FILE_PATH"
FILE_LIST="$FILE_LIST$(printf '\t\t\t\t%-19s' "$FILE_NM_DISP")$(printf '%-3s' ":")$(ls -ltr | grep -w "$c_date" | awk -F ' ' '{print "      "$6,$7,$8,$9}')"$'\n'
paste <(printf '  %-30s' "$FILE_LIST")

Output I am getting :-
Code:
Customer.log : Apr 24 16:31 Customer_Name_111121.txt
Apr 24 16:32 Customer_Name _111121. txt
Apr 24 16:34 Customer_Name_111112. txt
Apr 24 16:35 Customer_Name _222223. txt
Apr 24 16:37 Customer_Name_999999. txt
Brain-UCG.log : Apr 24 16:35 User_config_20140107.dat
Apr 24 16:36 User_config_20140110.dat
Apr 24 16:36 User_config_20140109.dat

Out put need to display :-
Code:
Customer.log  : Apr 24 16:31 Customer_Name_111121.txt
                               Apr 24 16:32 Customer_Name _111121. txt
                               Apr 24 16:34 Customer_Name_111112. txt
                              Apr 24 16:35 Customer_Name _222223. txt
                              Apr 24 16:37 Customer_Name_999999. txt
Brain-UCG.log : Apr 24 16:35 User_config_20140107.dat
                              Apr 24 16:36 User_config_20140110.dat
                              Apr 24 16:36 User_config_20140109.dat

Please suggest some good solution for this
# 7  
Old 05-05-2014
Hi guy's Any update?....I have tried many combinations, but not able to get proper formatted output ..please help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split multi columns line to 2 columns

I have data like this 1 a,b,c 2 a,c 3 b,d 4 e,f would like convert like this 1 a 1 b 1 c 2 a 2 c 3 b 3 d 4 e 4 f Please help me out (4 Replies)
Discussion started by: jhonnyrip
4 Replies

2. Shell Programming and Scripting

Sum of columns and format the output

Input file: 011100020100 0.00 1 20000 30000 20000 011110000025 0.00 1 000 240000 10000 011100020100 0.00 1 200000 2324000 403500 032200030025 0.00 1 2077500 3077500 250000 032200030025 0.00 1 2565000 25536400 320000 022220000005 0.00 1 10000 300000 300000 022220000005 0.00 1 200050... (7 Replies)
Discussion started by: vinus
7 Replies

3. Shell Programming and Scripting

Format output into columns, variables with multiple entries

Hello all, I've got a script that collects data on file systems and prints out specific data about each. I've formatted headers w/ printf like so. printf "\033 and I had the content of the varibles printed out beneath those columns like so: printf... (5 Replies)
Discussion started by: awreneau
5 Replies

4. UNIX for Dummies Questions & Answers

Appending columns at the end of output using awk/sed

Hi , I have the below ouput, =====gopi===== assasassaa adsadsadsdsada asdsadsadasdsa sadasdsadsd =====kannan=== asdasdasd sadasddsaasd adasdd =====hbk=== asasasssa .... .. I want the output like as below, not able paste here correctly. (2 Replies)
Discussion started by: eeegopikannan
2 Replies

5. Shell Programming and Scripting

incrementing lines in the file & format output.

Hi All, I need read the file and out put format as below using ksh, I wrote below script its keep on repeating first line in the file. may i know the best way to get the below out put while incrementing line in the file. cat b.txt |awk '{print $0}' |while read line do aa=`cat $line |head -1... (7 Replies)
Discussion started by: ashanabey
7 Replies

6. Shell Programming and Scripting

Appending the last few columns to the front

Hi consider this as the first line 00010015 MORGAN STANLEY & CO INCORPORATED N 110 INVESTAR 1 0001OT NJ 201-830-5055 01-Jan-1974 00:00:00 1 01-May-2008 00:00:00 05-Jun-2008 13:34:18 0001 - From SMSRun1_GIDQA02 Consider this as the second line 00010015 MORGAN STANLEY... (3 Replies)
Discussion started by: ragavhere
3 Replies

7. Shell Programming and Scripting

Cronjob - Redirect mail output to file, LINES & COLUMNS

I currently have an expect script that issues the 'mail' command and sends an 'x' when it receives the & prompt from mail to quit. The expect script is able to do stty rows 100 columns 200 < $spawn_out(slave,name) to set up the number of columns and rows. I would like to get rid of the expect... (0 Replies)
Discussion started by: jharvey
0 Replies

8. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„ÝÝ¡Š·œƒ.„ÝÝ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

9. Shell Programming and Scripting

need help appending lines/combining lines within a file...

Is there a way to combine two lines onto a single line...append the following line onto the previous line? I have the following file that contains some blank lines and some lines I would like to append to the previous line... current file: checking dsk c19t2d6 checking dsk c19t2d7 ... (2 Replies)
Discussion started by: mr_manny
2 Replies

10. Shell Programming and Scripting

Appending columns on a file

My issue is the following: I have several text files, let's say 10 of them. Each one has three columns separated by a tab: Date, Time and Value. What I want to do next is to have only one text file containing the information: Date, Time, Value1, Value2, Value3, ... , Value10, where Value1... (2 Replies)
Discussion started by: abel
2 Replies
Login or Register to Ask a Question