Column overruns in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Column overruns in bash
# 1  
Old 12-05-2012
Column overruns in bash

So say you have something like:

Code:
col1        col2        col3
.           .           .
.           .           .

Say using bash you want the columns to always have exactly the same width (including spaces). If there are text overruns, the overruns carry over to the next line.

I'm using something like:
Code:
printf "%s\t%-59s(%s)\n", col1, col2, col3

It so happens col1 text is always the same length. col2 varies big time, but I'd like to keep the column width at 59 chars. col3 begins at the end of col2.

If col2 is greater than 59 chars, I want it to continue over to the next line, directly beneath it.

Best way to go about this? Thanks!

Last edited by stevensw; 12-05-2012 at 09:41 PM..
# 2  
Old 12-05-2012
You can use an if condition to check if length of col2 is greater than 59 chars and print accordingly:-
Code:
if [ ${#col2} -gt 59 ]
then
      # print next line
else
      # print same line
fi

This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - delete from csv all the row if the first column is length >

Hi guys, i have a csv file like: USERID;COG;DESCR;FIL;OFF user001;user;test1;001;A01 user002;user;test2;002;A02 user0003;user;test3;003;A03 user004;user;test4;004;A04 user0005;user;test5;005;A05 etc.. I need to read line for line and, if value of first column is > 7 char (in this example... (4 Replies)
Discussion started by: kamose
4 Replies

2. Shell Programming and Scripting

Create a two column output in bash

Hi! I m newbie for scripting. My requirement is to create a host file as below from the output of aws api. Hostname PrivateIP abc x.y.x.z cde a.b.c.c and so on. I have the following script, #!/bin/bash export AWS_ACCESS_KEY=abc export... (5 Replies)
Discussion started by: cuteboyucsc
5 Replies

3. Shell Programming and Scripting

Update a mysql column via bash script

Hello, I want to check the value of all MySQL columns.(column name is "status") via bash script. If value is "0" at I want to make only single column value to "1" I have many "0" values on mysql database(on "status" column) "0" means it is a draft post. I want to publish a post. I... (2 Replies)
Discussion started by: tara123
2 Replies

4. Shell Programming and Scripting

Bash Replace value in specific column

Hi all, I have two files with the following format: file1 BBB;33 AAA;2 CCC;5 file2 5;.;.;. 33;.;.;. The first file contain a list of code and numbers. The second file only the number. I would like to replace the corresponding code in the first column of the file1 with the... (3 Replies)
Discussion started by: g256
3 Replies

5. Shell Programming and Scripting

Column parsing in a bash script - HELP

I would like to setup a script that pulls in time/date in two seperate columns, and then name the other columns as listed below: Column1=Art/TJ output Column2=Art/TJ output Column3=TJ output column4=Art output Column5=If time/date past 12:00 noon -fail Colume6=If time/date before... (1 Reply)
Discussion started by: walnutpony123
1 Replies

6. Shell Programming and Scripting

Replace last row of a column in bash/awk/sed

Hi, I've got a file with 3 columns which ends like this: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 1400 I want to replace the last row of the last column with the value 0. So my new file will end: ... 1234 345 1400 5287 733 1400 8472 874 1400 9317 726 ... (5 Replies)
Discussion started by: jhunter87
5 Replies

7. Shell Programming and Scripting

On the command line using bash, how do you split a string by column?

Input: MD5(secret.txt)= fe66cbf9d929934b09cc7e8be890522e MD5(secret2.txt)= asd123qwlkjgre5ug8je7hlt488dkr0p I want the results to look like these, respectively: MD5(secret.txt)= fe66cbf9 d929934b 09cc7e8b e890522e MD5(secret2.txt)= asd123qw lkjgre5u g8je7hlt 488dkr0p Basically, keeping... (11 Replies)
Discussion started by: teiji
11 Replies

8. UNIX for Dummies Questions & Answers

replace all numbers in column with another number in bash

Hi, I've been trying to replace the numbers in the first column of my text file with all ones, unless the number is equal to 8. I have this: 1 1 11 123 258 2 1 9 135 175 1 1 15 143 274 8 1 13 153 172 8 1 13 154 166 8 1 13 154 167 3 1 15 237 255 4 1 15 243 202 1 1 13 133 166... (4 Replies)
Discussion started by: goodbenito
4 Replies

9. Shell Programming and Scripting

How to read the value from a specific line and column BASH

Hi All, I have the same problem as the one posted in https://www.unix.com/shell-programming-scripting/96097-how-read-value-specific-line-column-csh-variable.html but I'm using bash. Can anyone tell me how I have to modify the code to make it bash compatible? eval `awk 'NR==3{print "set... (5 Replies)
Discussion started by: f_o_555
5 Replies

10. Shell Programming and Scripting

bash Column to array

Hi I have a file with just one column, and i'd like to save it in a bash array. file_in then, i want save the column in a bash array in order to get: array==word1, array==word2....array==word4 I can't figure out how to do it. Can anyone help please? thanks D EDIT: Sorry, i... (4 Replies)
Discussion started by: Dedalus
4 Replies
Login or Register to Ask a Question