insert "_" before uppercase letter with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting insert "_" before uppercase letter with awk
# 8  
Old 04-06-2011
Quote:
Originally Posted by bartus11
No idea. It is weird for me too.
Seems to be a local problem, change the LANG variable before launching awk:
Code:
LANG=C awk '{....}'

# 9  
Old 04-06-2011
As stated by Karel Zak on https://partner-bugzilla.redhat.com/....cgi?id=222270 :
-----------------------------------------------------------------------------------------------------------
The [a-z] defines range and not class of chars. It doesn't work correctly with
i18n environment, because locale sequence is defined as [aAbBcC..zZ] -- so [A-Z]
= [AbBCc..zZ].

You have to use [[:upper:]] or [[:lower:]]. (The old gawk 3.0.3 doesn't support
locales)

-----------------------------------------------------------------------------------------------------------

Code:
# gawk --version | head -2
GNU Awk 3.1.1
Copyright © 1998, 1991-2002 Free Software Foundation, Inc.

Code:
# echo 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ' | gawk '{gsub("[A-Z]","_&",$0)}1' IGNORECASE=0
a_A_b_B_c_C_d_D_e_E_f_F_g_G_h_H_i_I_j_J_k_K_l_L_m_M_n_N_o_O_p_P_q_Q_r_R_s_S_t_T_u_U_v_V_w_W_x_X_y_Y_z_Z
# echo 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ' | gawk '{gsub("[A-Z]","_&",$0)}1' IGNORECASE=1
_a_A_b_B_c_C_d_D_e_E_f_F_g_G_h_H_i_I_j_J_k_K_l_L_m_M_n_N_o_O_p_P_q_Q_r_R_s_S_t_T_u_U_v_V_w_W_x_X_y_Y_z_Z
#

Note the missing starting _ when IGNORECASE=0

Last edited by ctsgnb; 04-06-2011 at 01:38 PM..
# 10  
Old 04-07-2011
Lightbulb

Interesting, I'm running linux with GNU Awk 3.1.7 and LANG=C is good. Locales are a funny thing...thanks everybody Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

awk separate field by letter and ";"

i have a 2 fields in my DB ID25333,1429291340lNormPUC-AP_MEX_UFM-GOL_44;PUC-AP_VEX_UFM-ROL_55;PUCAP_MEX_UFM-DOJ_49; ID55555,1429291340lNormPUC-AP_PPP_UFM-HOL_44;PUC-AF_GEX_UJM-SOL_45;PUCAP_MEX_UFM-DOJ_59;and i need separate like this ID25333,PUC-AP_MEX_UFM-GOL_44; ... (5 Replies)
Discussion started by: Axl_north
5 Replies

3. Shell Programming and Scripting

awk if then "insert"

I have this output: FA-7H 5001438004c224b8 5001438005692b18 5001438005694778 500143800569491c 50014380056952e0 c0507604cc5c00a2 FA-10H 5001438004c224ba 5001438005692b1a 5001438005694372 500143800569477a 50014380056952e2 c0507604cc5c00a0 I would like this: FA-7H ... (2 Replies)
Discussion started by: elilmal
2 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

7. Shell Programming and Scripting

help for saving vertical datas to horizontal with "awk" or "cut"

hi, i have a file having datas like that ./a.txt 12344 12345 12346 12347 ..... ..... ... i want to save this datas to another file like that ./b.txt 12344 12345 12346 12347 ... ... ... i think awk can make this but how? :) waiting for ur help. (3 Replies)
Discussion started by: mercury
3 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question