Align with printf or other method


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Align with printf or other method
# 1  
Old 08-27-2014
Align with printf or other method

below line is one by one print
Code:
audio_play               PASS
boot_check                FAIL
ethernet_change_mac         NIC_82574L  PASS
gps_ublox_neo               FAIL
storage_bonnie              USB2        PASS
storage_copy_big_file      USB2        PASS

I would like below format
Code:
audio_play                               PASS
boot_check                               FAIL
ethernet_change_mac      NIC_82574L      PASS
gps_ublox_neo                            FAIL
storage_bonnie           USB2            PASS
storage_copy_big_file    USB2            PASS

# 2  
Old 08-27-2014
Printed by what?
# 3  
Old 08-27-2014
This is not easy unless the data you have is delimited or fixed length

You can easily convert from 1 step above
# 4  
Old 08-27-2014
Straightforward approach:
Code:
awk 'NF==3{printf "%-25s%-15s%s\n",$1,$2,$3; next}{printf "%-40s%s\n",$1,$2}' file

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 08-27-2014
Quote:
Originally Posted by RudiC
Printed by what?
by "printf" with line by line or other method , but I don't know how to
# 6  
Old 08-27-2014
Code:
column -t file

# 7  
Old 08-27-2014
What I meant is modify the script/program that prints the output in the first place instead of correcting the output afterwards. Slight modification of Scrutinizer's proposal:
Code:
awk 'NF<3{$3=$2;$2=""} {printf "%-25s%-15s%s\n",$1,$2,$3}' file
audio_play                              PASS
boot_check                              FAIL
ethernet_change_mac      NIC_82574L     PASS
gps_ublox_neo                           FAIL
storage_bonnie           USB2           PASS
storage_copy_big_file    USB2           PASS

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printf or any other method to put long string of spec characters - passing passwords

Hello, I am looking for a method to use in my bash script which allows me to use long strings with all special characters. I have found that printf method could be helpful for me but unfortunately, when I trying root@machine:~# tevar=`printf "%s%c"... (2 Replies)
Discussion started by: elxa1
2 Replies

2. Shell Programming and Scripting

Align columns

I have a text file that I filtered using awk. I only exctracted two columns. I want those two columns to be aligned. Most of the answers I found was to use `column -t` command. I tried that but I am getting a `bash: column: command not found`. Is there another way to align columns... (1 Reply)
Discussion started by: erin00
1 Replies

3. Shell Programming and Scripting

Re align in one row using sed

Hi, Anyone can help on how to re align my data in one row using sed. test.csv "url1","abc","project url1" 2016-08-16 "url2,"microsoft","project url2" 2016-08-18 need output like this "url1","abc","project url1","2016-08-16" "url2,"microsoft","project url2","2016-08-18" Thanks in... (8 Replies)
Discussion started by: fspalero
8 Replies

4. Shell Programming and Scripting

Align input fields on one under each other

Hello again, I'm having a issue with a contact form. I want the input fields to be aligned on same row and I really dont know how to do it. I attached a image for you to understand what i am trying to do. <BR> <label for="name" class="required"> Name&nbsp;<strong... (1 Reply)
Discussion started by: galford
1 Replies

5. Shell Programming and Scripting

Align columns

Hi, I have a question on how to align columns in shellscipt. SAMPLE 2015-07-15 09:01:00.0 |TCSERVER01 |10965 2015-07-15 09:02:00.0 |TCSERVER01 |4752 2015-07-15 09:03:00.0 |TCSERVER01 |4805 2015-07-15 09:04:00.0 |TCSERVER01 |3690 2015-07-15 09:01:00.0 |TCSERVER02 |8703 2015-07-15... (1 Reply)
Discussion started by: reignangel2003
1 Replies

6. Shell Programming and Scripting

Align data of the paragraph

Hi, I need your help to align data from paragraph. It's to : - delete the lign contain NDS - align data between paragraph start to "ND=" from second "ND=" example of file: @ ABOIL; @ CEN=1/15-05-23/09 H 06 MN 18/LISTAGE CARACTERISTIQUES D'ABONNES TRAITEMENT TGLAIL ACC... (1 Reply)
Discussion started by: vremen3
1 Replies

7. Shell Programming and Scripting

Align or move paragraph right

Hello I am a newbie in scripting and I am hoping someone may help with a method of aligning or tabbing selected text as its output. For example, using the SED command to extract paragraphs containing AA BBB CCC sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d' How could I say, get the... (18 Replies)
Discussion started by: lostincashe
18 Replies

8. Shell Programming and Scripting

Align the words

HI , I am new to shell scripting i m getting the below format like this Name FirstName Lastname ------ --------- ---------- Name1 Balaji NandaKishore Name123 Vijaya krsihna ... (5 Replies)
Discussion started by: Lucky123
5 Replies

9. Solaris

svc:/network/physical:default: Method "/lib/svc/method/net-physical" failed with exit status 96. [ n

After a memory upgrade all network interfaces are misconfigued. How do i resolve this issue. Below are some out puts.thanks. ifconfig: plumb: SIOCLIFADDIF: eg000g0:2: no such interface # ifconfig eg1000g0:2 plumb ifconfig: plumb: SIOCLIFADDIF: eg1000g0:2: no such interface # ifconfig... (2 Replies)
Discussion started by: andersonedouard
2 Replies

10. UNIX for Dummies Questions & Answers

Align Text from a file.

I need to align text from a file that has columns seperated by spaces and commas. Any ideas? Text is similar to this. File Name is Test. 05/14/06 13:46:56.575 ,TEST,5,123,1234,123,12345,12,12.2,2.1,4.5,5.23 05/14/06 13:49:58.009 ,TEST,6,456,456.7,45,4.56,453,34,54.3,3.2,6.456 (9 Replies)
Discussion started by: earlepps
9 Replies
Login or Register to Ask a Question