Table like formatting in Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Table like formatting in Linux
# 8  
Old 03-31-2018
Well then try enlarging the first column to 40:
Code:
awk -F'\t *' '{printf "%40-s%16-s%20-s%26-s%16-s%8-s%10-s%14-s%10-s%10-s%-s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11} NR==1{FS=","}' file

--edit--
As RudiC pointed out, the minus sign is in the wrong place, even though some awks seem to be tolerant of the different position, it is not correct..
Code:
awk -F'\t *' '{printf "%-40s%-16s%-20s%-26s%-16s%-8s%-10s%-14s%-10s%-10s%-s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11} NR==1{FS=","}' file

--
OR:, try making it flexible by first determining each max column width in the entire file and then read and process the file again using the max column widths:

Code:
awk '{for(i=1;i<=NF;i++){if(NR==FNR){l=length($i); if(l>W[i]) W[i]=l} else $i=sprintf("%-*s",W[i]+1,$i)}}1' FS='\t *|,' OFS= file file

Code:
SERVICE NAME            TEAM NAME CI OWNER          SECONDARY CONTACT PAYCHECK NAME DEVV ADEINT ENV DEV ENV STAGE ENV PROD ENV PROD 
accommodation           POSE      MatDon Richardson Chrivarian        Acc           Yes  Yes    Yes     Yes       Yes      Yes      
activitycodemappingtask DLLARS    Ian               Patrick           Acc           Yes  Yes    Yes     Yes       Yes      Yes      
activity-entity         Rega      Chang             John              TER           Yes  Yes    Yes     Yes       Yes      Yes      
api-test-runner         WRIGHT    Benson            Lehman            Lev           Yes  Yes    No      No        No       No       
assembly-service        Snap      Macdonald         Nikseth           Lev           Yes  Yes    Yes     No        No       Yes      
authorizationprocessing DLLARS    Ian               Pat               Acc           Yes  Yes    Yes     Yes       Yes      Yes

NOTE: the file is specified twice

Last edited by Scrutinizer; 04-01-2018 at 04:13 AM..
# 9  
Old 03-31-2018
Thank you for reply

Now most the rows are finely place..except few i will adjust position like you suggested.

only problem i see now is the header is row not aligned at all

it just normally printed seperated by commas
# 10  
Old 03-31-2018
You're welcome. Since it appears to work with the sample header row:
How does your real life header row differ from your sample header row.
# 11  
Old 03-31-2018
In post#5' sample, the header's field separators seem to be <TAB> characters, in the data line it's commas...
# 12  
Old 03-31-2018
@RudiC: Yes that is what posts #6 and #8 take into account.
# 13  
Old 04-01-2018
Those who can read ... I overlooked the redefinition of FS after the first line. Sorry!

Still I'm afraid the format specifiers should read %-40s (leading minus, not trailing) as correctly used in your post#8's second proposal.
This User Gave Thanks to RudiC For This Post:
# 14  
Old 04-01-2018
You are correct. It should be the other way around according to specification. However some awks (mine) seem to be tolerant to the switcheroo! Corrected in my posts.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

Formatting in a table via shell

Hi I have the below output: 736f14c4-eda2-4531-9d40-9de4d6d1fb0f An account already exists for this email address. Please enter a different email address. c3716baf-9bf8-42da-8a44-a13fff68d20f An account already exists for this email address. Please enter a different email address. Is... (4 Replies)
Discussion started by: ankur328
4 Replies

3. Shell Programming and Scripting

Build a table from a list by comparing existing table entries

I am new to this shell scripting.... I have a file which contains list of users. This files get updated when new user comes into the system. I want to create script which will give a table containing unique list of users. When I say unique, it means script should match table while parsing... (3 Replies)
Discussion started by: dchavan1901
3 Replies

4. Red Hat

Parsing a linux file and formatting it.

Hi, I have a linux file that has data like this.. REQUEST_ID|text^Ctext^Ctext^C REQUEST_ID|text^Ctext^C REQUEST_ID| REQUEST_ID| REQUEST_ID|text^Ctext^Ctext^Ctext^Ctext^Ctext^C.... Where ever I see a ^C character, I need to copy the corresponding REQUEST_ID and that part of the text to a new... (17 Replies)
Discussion started by: charithainfadev
17 Replies

5. Solaris

Linux partitioned disk mounted on OSOL without formatting

Hello and Merry Christmas... Quick question after tireless search around the web. Description: I have a WD My book world edition II that met an untimely death. However the 2 SATA disks inside seem to be working just fine. Want to add either one of them to my Solaris Desktop. Since I... (5 Replies)
Discussion started by: michnmi
5 Replies

6. Shell Programming and Scripting

Insert into Oracle table thru UNIX - linux 2.6.9-89

Hi, I am trying to insert a record into a table (say dips_tbl) which resides in Oracle DB through a ksh script. I want to insert records into few of the table columns-not all. I'll give an e.g. for the date column "CREATE_DATE". For that I first execute SQL1="SELECT SYSDATE FROM DUAL" ... (1 Reply)
Discussion started by: dips_ag
1 Replies

7. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

8. Shell Programming and Scripting

help on formatting output (Table Form)

Data in File ABC:DEFGHI:123 ABCZYE:DEFI:123 ABCFGD:DEF:123 ABCEERRRRR:DEFGHI:123 Expected Format 1 ABC DEFGHIFE 123 2 ABCZYE DEFI 123 3 ABCFGD DEF 123 4 ABCEERRRRR DEFGHI 123 However when i enter the following... (2 Replies)
Discussion started by: blurboy
2 Replies

9. Shell Programming and Scripting

How to obtain system open file table value in Linux

Hello , I want to get current system open file table value. Can any one help. Thanking you, mahesh (0 Replies)
Discussion started by: mahesh.
0 Replies
Login or Register to Ask a Question