Creating a column based list from a string list

Thread Tools Search this Thread
# 1  
Creating a column based list from a string list

I have a string containing fields separated by space


set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex"

and want to display it in a column format, for example to a maximum
of a window of 100 characters

And hopefully display some thing like

Fred       Ted       Joe       Peter      Paul      Jean
Chris      Tim       Tex

# 2  
printf "%s\t" $sr | fold -s

This User Gave Thanks to Corona688 For This Post:
# 3  
What have you tried so far and where exactly are you stuck?
# 4  
Forgot about fold. Works fine.

---------- Post updated at 12:53 PM ---------- Previous update was at 12:27 PM ----------

I have an additional question
set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex"

How can I find the longest field length. Here for example, the longest fields is of length 5.

---------- Post updated at 02:07 PM ---------- Previous update was at 12:53 PM ----------

I have now upgraded my work so that I create a table with the fields as I want.
The new code is shown. I have one little small problem that occasionally everything is shifted and would like to resolve this problem.

As the total width for fold is 80, I do not want fold to do anything but keep that field on one line instead of splitting it up.

Using for example
set arg_ierrLst = "-Fred -Ted -Joe -Peter -Paul -Jean--- -Chris -Tim -Tex ----Frodick -Ted -Joe -Peter- -Paul -Jean -Chris -Timd -Texdfgdfg"


-Fred        -Ted         -Joe         -Peter       -Paul        -Jean---     
-Chris       -Tim         -Tex         ----Frodick  -Ted         -Joe         
-Peter-      -Paul        -Jean        -Chris       -Timd        -Texdfgdfg

If field is longer than 80, for example,

set arg_ierrLst = "-Fred -Ted -Joe -Peter -Paul -Jean--- -Chris -Tim -Tex ----Frodick -Ted -Joe -Peter- -Paul -Jean -Chris -Timd -Texdfgdfg5fgfgfgfgfgfgf45678978766778776dfdfdfddfddfgdfgdfgdfgdfgfdfdfdfd7765434455666667"

I get


But when I use

set arg_ierrLst = "-Fred -Ted -Joe -Peter -Paul -Jean--- -Chris -Tim -Tex ----Frodick -Ted -Joe -Peter- -Paul -Jean -Chris -Timd -Texd5fgfgfgf7765434455666667"

I am getting

-Fred                          -Ted                           -Joe              
             -Peter                         -Paul                          
-Jean---                       -Chris                         -Tim              
             -Tex                           ----Frodick                    -Ted 
                          -Joe                           -Peter-                
        -Paul                          -Jean                          -Chris    

As you can see, sometimes the table get all messed up

  echo ""
  set wt = `echo "$arg_ierrLst" | tr " " "\n"  \
    | awk 'length($1) > length(mxStr) {mxStr=$1}; END{ print length(mxStr)+2}'`
  if ($wt <= 35) then
    echo "HERE 1"
    printf "%-"${wt}"s" $arg_ierrLst | fold -s
  else if (($wt > 35) && ($wt <= 80)) then
    echo "HERE 2"
    printf "%-s\t" $arg_ierrLst | fold -s
    echo "HERE 3"
    foreach f ($arg_ierrLst)
      echo "$f"


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Easy
The communication protocol NFC stands for Near-Field Control.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Creating list

how do i create a list of every process running on my system and place it into a file lets say p1.txt (1 Reply)
Discussion started by: richiestank
1 Replies

2. UNIX for Dummies Questions & Answers

Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function... Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

3. UNIX for Dummies Questions & Answers

Creating columns from a list

I have a list below, how can I have things separated nicely in columns mv browseDir.tcsh browseDir.csh mv checkSRDist.tcsh checkSRDist.csh mv create-data-tinv.tcsh create-data-tinv.csh mv createDocs.tcsh createDocs.csh mv createMisfit.tcsh createMisfit.csh mv createModel.tcsh... (4 Replies)
Discussion started by: kristinu
4 Replies

4. Shell Programming and Scripting

List of filenames where column title matches string and value is in limits

I'm somewhat new to BASH scripting but have managed to work my way through most of a problem. I'm trying to get a list of filenames where a column header occurs and any value in that column is within a range. So far I can sort through the list of files in a directory specified by the user, find... (5 Replies)
Discussion started by: hu_r_u2000
5 Replies

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

6. Shell Programming and Scripting

Splitting a list @list by space delimiter so i can access it by using $list[0 ..1..2]

EDIT : This is for perl @data2 = grep(/$data/, @list_now); This gives me @data2 as Printing data2 11 testzone1 running /zones/testzone1 ***-*****-****-*****-***** native shared But I really cant access data2 by its individual elements. $data2 is the entire list, while $data,2,3...... (1 Reply)
Discussion started by: shriyer
1 Replies

7. Shell Programming and Scripting

Creating a range out of a broken list

Hi all, I am trying to create a file which has one or more ranges based on a file containing a long list. The problem is that the file which has this list is not continuous and is broken in many places. I will try to illustrate by an example: The List File: 1 2 3 4 5 6 9 10 11 12... (5 Replies)
Discussion started by: run_time_error
5 Replies

8. UNIX for Dummies Questions & Answers

Creating a List of Files With Find

Hi, I need to go through all the files on my system and build a list/output file with the paths of all files where the first two characters within the file match an expression. I know I can use something like find . | xargs cut -b1-2 or find . -exec cut -b1-2 {} \; to get the characters... (3 Replies)
Discussion started by: 008_
3 Replies

9. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies

10. UNIX for Dummies Questions & Answers

creating a file with a list

I would like to create a text file that contains the list (names of files and dirs) of a particular directory... any ideas ? (5 Replies)
Discussion started by: hinman
5 Replies

Featured Tech Videos