|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[SOLVED] What is wrong with tiny (g)awk line ??
Hi I wish to capitalize the first letter or every word in a text file with: Code:
gawk '{$0=gensub(/(\w)(\w*)/,toupper("\\1")"\\2","g");}' file.txtBut it doesn't work...: target: bla test Test TEST yes nO Yes yes restult: bla test Test TEST yes nO Yes yes any idea? thanks Last edited by louisJ; 03-12-2012 at 05:58 AM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Code:
perl -pe 's/\b./\u$&/g' file.txt Last edited by tip78; 03-11-2012 at 09:37 AM.. |
|
#4
|
|||
|
|||
|
Thanks but the solution from this thread Code:
#for ( i=1; i <= NF; i++) {
# sub(".", substr(toupper($i),1,1),$i)
# }
printdoesn't capitalize this for example: I need " D'Alpinisme " instead of " D'alpinisme ".... and I really need awk. thanks |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
I am guessing the back reference \\1 does not get passed to the toupper function inside the replacement part of gawk's gensub function: Alternatively: Code:
awk '{for(i=1;i<=NF;i++)$i=toupper(substr($i,1,1)) substr($i,2)}1' infilebut that would squeeze spacing.. Or shortening the previous perl: Code:
perl -pe 's/\b./\u$&/g' infile |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
btw my solution works fine with d'alpinisme |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
tip78 ...the problem is with accentuated words lire Détente....your pearl gives DéTente.... |
| Sponsored Links | ||
|
![]() |
| Tags |
| awk gawk capital capitalize |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|