• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Textformatierung? Tabulatoren?

Morgähn! :)
Kann mir jemand sagen, wie ich Text formatieren kann mit der Shell? Bzw. geht das überhaupt? Ich bräuchte z.B. Tabulatoren für eine Art Tabelle... So ähnlich wie dieses Etikettenzeug neulich!

Also so in etwa...

blaaaaaaaaaa blaaaaaaaaa
blaaaaaaaaaa blaaaaaaaaa
blubblubblubbl blubblubblubl

Geht sowas?
 

regexer

Advanced Hacker
Lord_Levithanius schrieb:
Kann mir jemand sagen, wie ich Text formatieren kann mit der Shell?
Damit wir dein Problem verstehen, müsstest du es genauer beschreiben...
Natürlich kann die Schell mit Tabulatoren umgehen. Beispiel:
Code:
echo -e 'blaaaaaaaaaa\tblaaaaaaaaa'
 
Naja, es ist fast das gleiche, wie das mit den Adressen...Dieses Mal allerdings mit anderen Datensätzen. Also Daten aus Textdatei lesen und tabellenähnlich anordnen. Funktioniert auch wunderbar, aber durch die variierende Länge der Daten sieht das Ergebnis nicht ganz so toll aus... Eher so...

wert1__wert2____wert3_wert4__wert5
wert6_wert7__wert8_wert9_____wert10

Und es soll einfach hübsch aussehen, wie ne richtige Tabelle ;)

Vllt. irgendwas mit cut?
 

regexer

Advanced Hacker
Lord_Levithanius schrieb:
wert1__wert2____wert3_wert4__wert5
wert6_wert7__wert8_wert9_____wert10

Und es soll einfach hübsch aussehen, wie ne richtige Tabelle ;)
Es gibt sicher mehrere Wege. Hier ist meiner:
Code:
prompt> typeset -L8 bla   # linksbuendig, 8 Zeichen
prompt> bla=x
prompt> echo "$bla $bla"
x        x       
prompt> bla=xxxxxxxxxxxxxxx  
prompt> echo "$bla $bla"
xxxxxxxx xxxxxxxx
In meinem Beispiel werden Werte länger als 8 Zeichen abgeschnitten. Man könnte natürlich erst den längsten Wert ermitteln...
 

regexer

Advanced Hacker
oder printf nehmen. Das würde dann nicht abschneiden, sondern verschieben:
Code:
prompt> printf "%-8s %-8s %-8s\n" 1234 1234 1234
1234     1234     1234
prompt> printf "%-8s %-8s %-8s\n" 1234 1234567890 1234
1234     1234567890 1234
 

TeXpert

Guru
entweder so oder etwas mehr String-Coding --> schau noch mal in das Adress-dingen von mir rein, da hab ich die ja auch auf fixe Breite gebracht.
 
Das Ding mit typeset funktioniert irgendwie nicht...

Code:
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...

In den man-pages kann ich auch nichts mit typeset und "-L" finden...
Hmm, dann werde ich mich wohl mit dem Stringzeugs auseinander setzen...
 

TeXpert

Guru
Lord_Levithanius schrieb:
In den man-pages kann ich auch nichts mit typeset und "-L" finden...

man bash -> suche nach typeset

manpage von bash schrieb:
typeset [-afFirtx] [-p] [name[=value]]
Declare variables and/or give them attributes. If no names are given then display the values of variables. The
-p option will display the attributes and values of each name. When -p is used, additional options are ignored.
The -F option inhibits the display of function definitions; only the function name and attributes are printed.
The -F option implies -f. The following options can be used to restrict output to variables with the specified
attribute or to give variables attributes:
-a Each name is an array variable (see Arrays above).
-f Use function names only.
-i The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION ) is performed
when the variable is assigned a value.
-r Make names readonly. These names cannot then be assigned values by subsequent assignment statements or
unset.
-t Give each name the trace attribute. Traced functions inherit the DEBUG trap from the calling shell. The
trace attribute has no special meaning for variables.
-x Mark names for export to subsequent commands via the environment.

Using `+' instead of `-' turns off the attribute instead, with the exception that +a may not be used to destroy
an array variable. When used in a function, makes each name local, as with the local command. The return value
is 0 unless an invalid option is encountered, an attempt is made to define a function using ``-f foo=bar'', an
attempt is made to assign a value to a readonly variable, an attempt is made to assign a value to an array vari-
able without using the compound assignment syntax (see Arrays above), one of the names is not a valid shell
variable name, an attempt is made to turn off readonly status for a readonly variable, an attempt is made to
turn off array status for an array variable, or an attempt is made to display a non-existent function with -f.
 

regexer

Advanced Hacker
TeXpert schrieb:
man bash -> suche nach typeset
Ja! War mein Fehler. man ksh -> suche nach typeset:
Code:
       typeset [[±Ulprtux] [-L[n]] [-R[n]] [-Z[n]] [-i[n]]  |  -f
       [-tux]] [name[=value] ...]
[...]
 -Ln  Left justify attribute: n specifies the field
      width.   If  n  is not specified, the current
      width of a parameter (or  the  width  of  its
      first assigned value) is used.  Leading white
      space (and zeros, if used with the -Z option)
      is stripped.  If necessary, values are either
      truncated or space padded to  fit  the  field
      width.
Naja, das nützt wohl nichts in der bash...
 
Oben