Sponsored Content
Top Forums Shell Programming and Scripting How to print out with equal spacing between columns? Post 303043185 by TestKing on Monday 20th of January 2020 10:38:27 PM
Old 01-20-2020
How to print out with equal spacing between columns?

For instance, my file contains the following content...
Code:
    set -A array
    set -A test
    ${array[0]}=1
    ${array[1]}=2
    ${array[2]}=3
    ${test[0]}="Boy"
    ${test[1]}="Girl"
    ${test[2]}="Dog"
    x=0
    while [ $x -lt 3 ];do
          print "${array[$x]}" " " "${test[$x]}"
          x=$((x+1)
    done

As you can I have to manually control the spacing between the printing of the columns....I think I saw like
Code:
    printf "%3s %-4s" "${array[$x]}" "${test[$x]}"

Apparently, it isn't working as it printed out
Code:
      1Boy
      2Girl
      3Dog

..................
Unless I do like
Code:
     printf "%s %s" "${array[$x]}" " " " ${test[$x]}"

it will print out like I wanted
Code:
     1 Boy
     2 Girl
     3 Dog

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Threshold is less than 0.003 or equal then print the line

Friends, I have very large data files (File1 and File2). Search field1 of File1 into Field1 of File2. If found then do Field1 of File1 MINUS Field1 of File2 if the answer is <= 0.003 (positive or negative) then print that line from File1. File1 ABC1231|1.1111|2.2122|3.3133... (3 Replies)
Discussion started by: ppat7046
3 Replies

2. Programming

Catch signal SIGPIPE print errno but it's value equal to 2

catch signal SIGPIPE ,print errno but it's value equal to 2(ENOENT) #define ENOENT 2 /* No such file or directory */ is it should be EPIPE ? #define EPIPE 32 /* Broken pipe */ Thanks ! (7 Replies)
Discussion started by: aobai
7 Replies

3. Shell Programming and Scripting

File name has double spacing, but after print it's gone

Hi, I am writing this script to find all files in a directory and print the filepath, date and file size. However, it doesnt seem to preserve double spacing file with this script. I would appreciate a pointer or 2 to get around this - printf("%s ",$i) is printing the filepath, what do... (3 Replies)
Discussion started by: nightrider
3 Replies

4. Shell Programming and Scripting

compare columns for equal values and output a summary

Hi all I am trying to scan a file that has 3 columns: red blue 123351 red blue 848655 red blue 126354 red blue 023158 black white 654896 red blue 650884 I want an output that sums the rows that have matching columns 1 and 2 :wall: red blue has 5 entries black white has 1 entry ... (4 Replies)
Discussion started by: reno
4 Replies

5. Shell Programming and Scripting

How to echo columns with consistent spacing?

for (.....) echo -e "$Name | $Age | $Sex\t|$Grade\t\t" done output: John |12 |Male |6th Jack |15 |Male |8th Zachary |15 |Male |9th I want the lines to line up...but it's out of line when the name is long (2 Replies)
Discussion started by: etranman1
2 Replies

6. Shell Programming and Scripting

Using awk, print all the lines where field 8 is equal to x

Using awk, print all the lines where field 8 is equal to x I really did try, but this awk thing is really hard to figure out. file1.txt"Georgia","Atlanta","2011-11-02","x","","","","" "California","Los Angeles","2011-11-03","x","","","",""... (2 Replies)
Discussion started by: charles33
2 Replies

7. UNIX for Dummies Questions & Answers

Define spacing of columns

Hi! I need to change the spacing assigned to each number in a text file. I have an input file with 5 columns and 3 rows. Here, all numbers are separated by 1 space. I need to change this in such a way that the number in the first column has 6, the number in the second column has 5 and all other... (2 Replies)
Discussion started by: Alauda
2 Replies

8. Shell Programming and Scripting

awk to print record not equal specific pattern

how to use "awk" to print any record has pattern not equal ? for example my file has 5 records & I need to get all lines which $1=10 or 20 , $2=10 or 20 and $3 greater than "130302" as it shown : 10 20 1303252348212B030 20 10 1303242348212B030 40 34 1303252348212B030 10 20 ... (14 Replies)
Discussion started by: arm
14 Replies

9. Shell Programming and Scripting

If first character doesn't equal '#' and same line contains 'temp', print everything else

(2 Replies)
Discussion started by: snoman1
2 Replies

10. UNIX for Dummies Questions & Answers

Want the UNIX code - I want to sum of the 1st column wherever the first 2nd and 3rd columns r equal

I have the code for the below things.. File1 has the content as below 8859 0 subscriberCreate 18 0 subscriberPaymentMethodChange 1650 0 subscriberProfileUpdate 7668 0 subscriberStatusChange 13 4020100 subscriberProfileUpdate 1 4020129 subscriberStatusChange 2 4020307 subscriberCreate 8831... (5 Replies)
Discussion started by: Mahen
5 Replies
Imager::Probe(3pm)					User Contributed Perl Documentation					Imager::Probe(3pm)

NAME
Imager::Probe - hot needle of inquiry for libraries SYNOPSIS
require Imager::Probe; my %probe = ( # short name of what we're looking for (displayed to user) name => "FOO", # pkg-config lookup pkg => [ qw/name1 name2 name3/ ], # perl subs that probe for the library code => [ &foo_probe1, &foo_probe2 ], # or just: code => &foo_probe, inccheck => sub { ... }, libcheck => sub { ... }, # search for this library if libcheck not supplied libbase => "foo", # library link time options, uses libbase to build options otherwise libopts => "-lfoo", # C code to check the library is sane testcode => "...", # header files needed testcodeheaders => [ "stdio.h", "foo.h" ], ); my $result = Imager::Probe->probe(\%probe) or print "Foo library not found: ",Imager::Probe->error; DESCRIPTION
Does the probes that were hidden in Imager's Makefile.PL, pulled out so the file format libraries can be externalized. The return value is either nothing if the probe fails, or a hash containing: o "INC" - "-I" and other C options o "LIBS" - "-L", "-l" and other link-time options o "DEFINE" - "-D" options, if any. The possible values for the hash supplied to the probe() method are: o "pkg" - an array of pkg-config names to probe for. If the pkg-config checks pass, "inccheck" and "libcheck" aren't used. o "inccheck" - a code reference that checks if the supplied include directory contains the required header files. o "libcheck" - a code reference that checks if the supplied library directory contains the required library files. Note: the Makefile.PL version of this was supplied all of the library file names instead. "libcheck" can also be an arrayref of library check code references, all of which must find a match for the library to be considered "found". o "libbase" - if "inccheck" is supplied, but "libcheck" isn't, then a "libcheck" that checks for "lib"libbase$Config{_a} and "lib"libbase.$Config{so} is created. If "libopts" isn't supplied then that can be synthesized as "-llibbase". "libbase" can also be an arrayref of library base names to search for, in which case all of the libraries mentioned must be found for the probe to succeed. o "libopts" - if the libraries are found via "inccheck"/"libcheck", these are the "-l" options to supply during the link phase. o "code" - a code reference to perform custom checks. Returns the probe result directly. Can also be an array ref of functions to call. o "testcode" - test C code that is run with Devel::CheckLib. You also need to set "testcodeheaders". o "testcodeprologue" - C code to insert between the headers and the main function. o "incpath" - $Config{path_sep} separated list of header file directories to check, or a reference to an array of such. o "libpath" - $Config{path_sep} separated list of library file directories to check, or a reference to an array of such. o "alternatives" - an optional array reference of alternate configurations (as hash references) to test if the primary configuration isn't successful. Each alternative should include an "altname" key describing the alternative. Any key not mentioned in an alternative defaults to the value from the main configuration. perl v5.14.2 2012-04-29 Imager::Probe(3pm)
All times are GMT -4. The time now is 04:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy