[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [TEKNIK] pad'e en string i bash



Hej!

On 090310 23:56, Atte André Jensen wrote:
> Hejsa
>
> Jeg vil gerne pad'e en string i bash. Følgende lille bogus script viser  
> problemstillingen:
>
> #!/bin/bash
> for file in `ls *.txt`; do
>     echo $file `stat -c %Y $file` ALIGN
> done
>
> sslug@sslug:~$ pad.sh
> anagrammer_oeveoptagelser_track_list.txt 1232703567 ALIGN
> jack_update.txt 1234444855 ALIGN
> test.txt 1226059095 ALIGN
>
> Men jeg ønsker fx:
> anagrammer_oeveoptagelser_track_list.txt     1232703567    ALIGN
> jack_update.txt                              1234444855    ALIGN
> test.txt                                     1226059095    ALIGN
>
> Og hvis anden kolonne havde haft varierende bredde:
> anagrammer_oeveoptagelser_track_list.txt     1232703567    ALIGN
> jack_update.txt                                      55    ALIGN
> test.txt                                        6059095    ALIGN
>
> Hvordan gøres dette smartest i bash. Måske skal jeg slet ikke pad'e, men  
> gribe det an på en anden måde.

printf är väl en lösning.

t.ex:

for file in `ls *.pl`; do 
        printf '%-16s %8d ALIGN\n' "$file" "`stat -c %Y $file`"; 
done

output:
deny.pl          1236725431 ALIGN
netlogon.pl      1232640416 ALIGN

-- 
Olof Johansson                                       <sslug@sslug>
http://www.ethup.se                                       0x7FC0FBBA      


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2009-04-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *