Sponsored Content
Top Forums Shell Programming and Scripting Table like formatting in Linux Post 303015254 by onenessboy on Saturday 31st of March 2018 10:18:46 AM
Old 03-31-2018
Quote:
Originally Posted by RudiC
What do you need the SERVICE=$1 for? The SERVICE variable is not used anywhere in your code...

Try to adapt Scrutinizer's code (you were close in your commented out samples):
Code:
awk -F, -v keyword="$1" 'NR == 1 || $1 == keyword {printf "%12-s\t%9-s\t%8-s\t%17-s\t%13-s\t%4-s\t%6-s\t%7-s\t%9-s\t%8-s\t%8-s\n",$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11}' /opt/scripts/devv/book7.csv

Check for the correct field separator.
Please be aware that $1 in shell differs from $1 in awk.
Dear RudiC,

Thanks for followup reply.

SERVICE=$1 is input parameter that i want to pass in while executing my shell script
and data for this parameter is available in book.7 csv file
and I shall run program as below
$asp > sh test7.sh checkout -- in this checkout one of value for columna called SERVICE in of that csv file

by passing this service name i should get relevant row from that csv and display it on screen both header and its record..


and now problem is with the formatting.. I want to display it strict tabular format, but header and child record are not aligning together properly

Here is some sample data in that csv: The challenge is actual data is vary in length ..the code that i am trying working (in the sense aligning correctly and for some its not aligning correctly. In true sense the problem Column header should adjust according to rows (i.e data rows) not vice versa.. which i am trying to achieve

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

for example ; the below service having slight larger length paycheck name hence format is disturbed. you can see COLUMN Heading SECONADARY CONTACT NOT ALIGNED, PAYCHECK VALUE not aligned properly, However in CSV file data does not have any extra spaces it looks perfect like above sample data.
Code:
SERVICE NAME	TEAM NAME	CI OWNER 	SECONDARY CONTACT	PAYCHECK NAME	DEVV	ADEINT	ENV DEV	  ENV STAGE	ENV PROD	    ENV PROD
     cmc                   MULTIPLE     Timothy sutherland     Wills Robinson                              TER or LEV depending on plugin  Yes     Yes     Yes     Yes             Yes             Yes


Last edited by Scrutinizer; 03-31-2018 at 12:22 PM.. Reason: code tags again
 

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

9. 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
All times are GMT -4. The time now is 09:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy