Creating columns from a list


 
Thread Tools Search this Thread
# 1  
Creating columns from a list

I have a list below, how can I have things separated nicely in columns

Code:
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 createModel.csh
mv createTrvt.tcsh createTrvt.csh
mv hseis-processing.tcsh hseis-processing.csh
mv plotMisfit.tcsh plotMisfit.csh
mv plotModel.tcsh plotModel.csh

to look like this

Code:
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         createModel.csh
mv createTrvt.tcsh          createTrvt.csh
mv hseis-processing.tcsh    hseis-processing.csh
mv plotMisfit.tcsh          plotMisfit.csh
mv plotModel.tcsh           plotModel.csh

# 2  
Code:
perl -ane 'printf "%s %s%25s\n", $F[0], $F[1], $F[2]' inputfile


Last edited by balajesuri; 01-12-2012 at 07:46 AM..
# 3  
The command works fine, however I have a script like below and just doing an echo, rather than having the things in a file.

Code:
foreach f ($fullNamesLst)
  set match = `echo $f | grep $src`
  if ("$match" != "") then                             # filename matches source
    set fname = `echo $f | awk 'BEGIN {FS="."} {print $1}'`
    set fext = `echo $f | awk 'BEGIN {FS="."} {print $2}'`
    set fout = `echo $f | awk -v s=$src -v d=$dst '{sub(s,d); print}'`
    if ($opt_execute == 0) then
      if ($imsg == 1) then
        echo "--Commands to run--------------------------------------------------------------------"
        echo ""
        set imsg = 0
      endif
      if ( $fext != "run" ) then
        echo "mv $f $fout"
      endif
    else
      if ($imsg == 1) then
        echo "--Executed commands------------------------------------------------------------------"
        echo ""
        set imsg = 0
      endif
      if ( $fext != "run" ) then
        echo "mv $f $fout"
        mv $f $fout
      endif
    endif
  endif
end

# 4  
Instead of echo use this:
Code:
printf "mv %25s%25s" $f $fout

# 5  
Got it. I have now used a variable so I can set the column width as I wish.

Code:
printf "%s %s %${cwid}s\n" "mv" $f $fout

---------- Post updated at 09:41 AM ---------- Previous update was at 07:06 AM ----------

Quote:
Originally Posted by balajesuri
Code:
perl -ane 'printf "%s %s%25s\n", $F[0], $F[1], $F[2]' inputfile

I have tried to do the perl thing with a variable width in a script but is not working.
If I put a fixed number things work out fine.

Code:
perl -ane 'printf "%s %s%${wtCol}s\n", $F[0], $F[1], $F[2]' ./$frun

---------- Post updated at 10:00 AM ---------- Previous update was at 09:41 AM ----------

I am trying the thing below but have problem putting w in the printf.

Code:
awk '{printf "%s %s%ws\n", $1, $2, $3}' w=${wtCol} ./$frun

---------- Post updated at 10:37 AM ---------- Previous update was at 10:00 AM ----------

Problem now fixed
Code:
set mxLenF2 = `awk 'length($2) > length(mxStr) {mxStr=$2}; END{ print length(mxStr)}' ./$frun`
set mxLenF3 = `awk 'length($3) > length(mxStr) {mxStr=$3}; END{ print length(mxStr)}' ./$frun`
awk '{printf "%s %-"w2"s %-"w3"s\n", $1, $2, $3}' w2=${mxLenF2} w3=${mxLenF3} ./$frun

 

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

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. Shell Programming and Scripting

Creating a loop for multiplying columns

I have 2 files, that look like this: ID SNP1 SNP2 SNP3 SNP4 A1 1 2 0 2 A2 2 0 1 1 A3 0 2 NA 1 A4 1 1 0 2 and this: SNP score SNP1 0.5 SNP2 0.7 SNP3 0.8 SNP4 0.2 Basically, all of the SNP-values are 0,1, 2 or NA, and they each have a score, listed in the second file. The total... (5 Replies)
Discussion started by: kayakj
5 Replies

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

4. Shell Programming and Scripting

Creating subset of a file based on specific columns

Hello Unix experts, I need a help to create a subset file. I know with cut comand, its very easy to select many different columns, or threshold. But here I have a bit problem as in my data file is big. And I don't want to identify the column numbers or names manually. I am trying to find any... (7 Replies)
Discussion started by: smitra
7 Replies

5. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example 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 ... (3 Replies)
Discussion started by: kristinu
3 Replies

6. UNIX for Dummies Questions & Answers

Help creating well-formatted columns

Hi all I'm having a few issues with sorting some data into easily-readable columns. Original data in file: Number of visits IP Address 8 244.44.145.122 8 234.45.165.125 6 225.107.26.10 I firstly tried the column -t command which results in this: Number of ... (4 Replies)
Discussion started by: semaj
4 Replies

7. Solaris

Creating script adding 3 different variables in 3 columns

I have 3 variables with different information.. they look like this (row-wise aswell): Variable1 = Roland Kalle Dalius Variable2 = ake123 ler321 kaf434 Variable3 = Richardsen Sworden Lokthar How can I sort them by variable3 alphabetical and add them into the same output so... (0 Replies)
Discussion started by: Prantare
0 Replies

8. Programming

Creating a table like format with rows and columns

I have few files which have two columns in each. like e2 1 1 2694 2 4 2485 3 2 2098 5 1 2079 6 5 2022 9 4 1734 11 5 1585 13 2 1461 18 1 1092 21 2 1019 24 1 915 25 3 907 27 1 891 28 3 890 34 1 748 39 1 700 (1 Reply)
Discussion started by: kamuju
1 Replies

9. UNIX for Dummies Questions & Answers

Creating a list of files in directory?

Hi All, I would like to do a loop on all the files with extension .out in my directory this files should be sorted alphabetically. Then I need to assign to each of them a progressive ID of three digits (maybe in HEX format?). First I tried to list manually the files as ARRAY=( A-001.out ... (5 Replies)
Discussion started by: f_o_555
5 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