Creating a column based list from a string list


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Creating a column based list from a string list
# 1  
Old 01-12-2012
Creating a column based list from a string list

I have a string containing fields separated by space

Example

Code:
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

Code:
Fred       Ted       Joe       Peter      Paul      Jean
Chris      Tim       Tex

# 2  
Old 01-12-2012
Code:
printf "%s\t" $sr | fold -s

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

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

I have an additional question
Code:
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
Code:
set arg_ierrLst = "-Fred -Ted -Joe -Peter -Paul -Jean--- -Chris -Tim -Tex ----Frodick -Ted -Joe -Peter- -Paul -Jean -Chris -Timd -Texdfgdfg"

gives

Code:
-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,

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

I get

Code:
-Fred
-Ted
-Joe
-Peter
-Paul
-Jean---
-Chris
-Tim
-Tex
----Frodick
-Ted
-Joe
-Peter-
-Paul
-Jean
-Chris
-Timd
-Texdfgdfg5fgfgfgfgfgfgf45678978766778776dfdfdfddfddfgdfgdfgdfgdfgfdfdfdfd7765434455666667

But when I use

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

I am getting

Code:
-Fred                          -Ted                           -Joe              
             -Peter                         -Paul                          
-Jean---                       -Chris                         -Tim              
             -Tex                           ----Frodick                    -Ted 
                          -Joe                           -Peter-                
        -Paul                          -Jean                          -Chris    
                     -Timd                          
-Texd5fgfgfgf7765434455666667

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

Code:
  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
  else
    echo "HERE 3"
    foreach f ($arg_ierrLst)
      echo "$f"
    end
  endif

 
Login or Register to Ask a Question

Previous Thread | Next Thread

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

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

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

10. HP-UX

creating a mailng list for mailx

I'm trying recall how to set up a script to have mailx read a mailing list of people to recieve a message. I had set up the script to have every name inside but the list could grow and/or change. can any one help? I'm using HPUX 11 on a rp7410. (6 Replies)
Discussion started by: rfmurphy_6
6 Replies
Login or Register to Ask a Question