Presenting data in column format

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Presenting data in column format
# 1  
Old 11-14-2016
Presenting data in column format

I have written a script that that takes file names and breaks them apart.

File names are :

Code:
aal_mock.war.deployed
AuroralMockService-1.0.war.deployed
consumerProfile.war.deployed
EbillMock.war.deployed
IAMAOGServices.war.deployed
IAMPermission.war.deployed
notificationservice.war.deployed
tibco_mock.war.deployed
tmo-iam-aa.war.deployed
tmo-iam-pm.war.deployed
tmo-iam-privacyvault.war.deployed
tmo-iam-provisioning.war.deployed
tmo-iam-provisioning.war.undeployed

I want to present the data like

Code:
aal_mock                      deployed
consumerProfile              deployed
EbillMock                       deployed
IAMAOGServices             deployed
IAMPermission               deployed
notificationservice           deployed
tibco_mock                    deployed
tmo-iam-aa                   deployed
tmo-iam-pm                  deployed
tmo-iam-privacyvault      deployed
tmo-iam-provisioning      deployed
tmo-iam-provisioning      undeployed

But the result I am getting is like :

Code:
aal_mock      deployed
consumerProfile      deployed
EbillMock      deployed
IAMAOGServices      deployed
IAMPermission      deployed
notificationservice      deployed
tibco_mock      deployed
tmo-iam-aa      deployed
tmo-iam-pm      deployed
tmo-iam-privacyvault      deployed
tmo-iam-provisioning      deployed
tmo-iam-provisioning      undeployed

I basically want to format it like 2 columns.

The script is :

Code:
#!/bin/bash


for file in /tmp/test/*war.* ; do
   NAME=`ls -ltrh ${file} | cut -d/ -f4 | cut -d. -f1`
   STATE=`ls -ltrh ${file} | cut -d. -f4`

echo "${NAME}      ${STATE}"
done

I can I indent it properly ?
# 2  
Old 11-14-2016
Run as ./script.sh /tmp/test or perhaps ./script.sh if you are in /tmp/test and scritp.sh lives there.

Code:
#!/bin/bash

path_base="${@:-.}"
for f in "${path_base}"/*war.*; do
  name="${f##*/}" # strip path
  name="${name%.war.*}" # clean name
  name="${name%-[0-9]*}" # strip versioning is any
  state="${f##*.}" # obtain state
  printf "%-25s %s\n" "$name" "$state"
done

This User Gave Thanks to Aia For This Post:
# 3  
Old 11-14-2016
Code:
printf "%-25s %s\n" "$name" "$state"

I believe the above line is what was missing. Thank you Smilie
# 4  
Old 11-14-2016
Quote:
Originally Posted by Junaid Subhani
Code:
printf "%-25s %s\n" "$name" "$state"

I believe the above line is what was missing. Thank you Smilie
You can pick whatever you would like to use. I just shown you a more efficient way of extracting the fields you want.
This User Gave Thanks to Aia For This Post:
# 5  
Old 11-15-2016
You might also try:
Code:
#!/bin/bash
cd /tmp/test
for file in *war.*
do	printf '%-25s %s\n' "${file%%.*}" "${file##*.}"
done

which, with the files you said were in that directory, produces the output:
Code:
AuroralMockService-1      deployed
EbillMock                 deployed
IAMAOGServices            deployed
IAMPermission             deployed
aal_mock                  deployed
consumerProfile           deployed
notificationservice       deployed
tibco_mock                deployed
tmo-iam-aa                deployed
tmo-iam-pm                deployed
tmo-iam-privacyvault      deployed
tmo-iam-provisioning      deployed
tmo-iam-provisioning      undeployed

This produces output in alphabetic order (instead of reverse modification time order) and the line shown in red does not appear in the output you said you wanted. Since most of the names you provided only contain two decimal points, I don't see how your code produced the output you said it did, but maybe this will give you some other ideas for extracting the data you want. If reverse time order is important, you could also try:
Code:
#!/bin/bash
cd /tmp/test
ls -tr *war.* | while IFS= read -r file
do	printf '%-25s %s\n' "${file%%.*}" "${file##*.}"
done

# 6  
Old 11-15-2016
Hi.

A kind of automatic alignment can be done with align:
Code:
$ align data1 
aal_mock             deployed
consumerProfile      deployed
EbillMock            deployed
IAMAOGServices       deployed
IAMPermission        deployed
notificationservice  deployed
tibco_mock           deployed
tmo-iam-aa           deployed
tmo-iam-pm           deployed
tmo-iam-privacyvault deployed
tmo-iam-provisioning deployed
tmo-iam-provisioning undeployed

or, if more space is desired, increase the gutter:
Code:
$ align -g 10 data1 
aal_mock                      deployed
consumerProfile               deployed
EbillMock                     deployed
IAMAOGServices                deployed
IAMPermission                 deployed
notificationservice           deployed
tibco_mock                    deployed
tmo-iam-aa                    deployed
tmo-iam-pm                    deployed
tmo-iam-privacyvault          deployed
tmo-iam-provisioning          deployed
tmo-iam-provisioning          undeployed

On my system:
Code:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.6 (jessie) 
align 1.7.0

Characteristics of align:
Code:
align   Align columns of text. (what)
Path    : ~/p/stm/common/scripts/align
Length  : 270 lines
Type    : Perl script, ASCII text executable
Shebang : #!/usr/bin/perl
Help    : probably available with --help

And align can be found at:
align: text column alignment filter

Best wishes ... cheers, drl

Last edited by drl; 11-15-2016 at 10:05 PM.. Reason: Edit 1: minor typo
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change data in one column with data from another file's column

Hello, I have this file outputData: # cat /tmp/outputData __Capacity^6^NBSC01_Licences^L3_functionality_for_ESB_switch __Capacity^2100^NBSC01_Licences^Gb_over_IP __Capacity^1837^NBSC01_Licences^EDGE_BSS_Fnc __Capacity^1816^NBSC01_Licences^GPRS_CS3_and_CS4... (1 Reply)
Discussion started by: nypreH
1 Replies

2. UNIX for Dummies Questions & Answers

Des/awk for change format and adding integers in a column of data?

Greetings! I need a quick way to change the format in a table of data Here is an example of the input: 10 72 Value=177 VDB=0.0245 Value4=0,0,171,0 10 274 Value=238 VDB=0.0433 Value4=29,0,205,0 10 312 Value=222 VDB=0.0384 Value4=8,0,190,19 10 540 Value=405 VDB=0.0391 Value4=13,30,153,195... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

3. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

4. UNIX for Dummies Questions & Answers

Changing data format from column into array

I have a file containing numbers in a column like: 10.5 16.3 15.7 2.3 46.8 3.3 . . . and I was wondering if there was a way to make it show up in an array form like: 10.5 2.3 16.3 46.8 15.7 3.3 Let's say I want to make a new column every 100 values. How can I do... (8 Replies)
Discussion started by: ShiGua
8 Replies

5. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

6. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

7. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

9. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies
Login or Register to Ask a Question