awk gsub

awk -F ',' '{for(i=1;i<=NF;i++){gsub(/^"/,"",$i);gsub(/"$/,"",$i);}{ print $0}}' t.csv

awk -F ',' '{gsub(/^"/,"",$1);gsub(/"$/,"",$1);gsub(/^"/,"",$2);gsub(/"$/,"",$2);  { print $0} }' t.csv

gawk -v FIELDWIDTHS='11 3 1 2 6 5' -v -OFS='\001' '{$1=$1 "";print}'  /xxxxx/xxxx/test.txt

[hadoop@hadoopmaster test]$ awk -F ',' '{for(i=1;i<=NF;i++){gsub(/^"/,"",$i);gsub(/"$/,"",$i);}{ print $0}}' t.csv
1 jaabc\"ss\"ck
2,abc
[hadoop@hadoopmaster test]$ cat t.csv
"1","jaabc\"ss\"ck"
2,abc
[hadoop@hadoopmaster test]$



[hadoop@hadoopmaster ~]$ a=`hive -e "select count(1) from default.test2" 2>/dev/null`
[hadoop@hadoopmaster ~]$ echo $a
7


du -sh /root/*|sort -rn





[root@linuxstudy fixlengthtest]# awk -v FIELDWIDTHS="1 1 1 6" -v OFS="|" '{for(i=1;i<=NF;i++){gsub(/^[[:blank:]]*/,"",$i);gsub(/[[:blank:]]*$/,"",$i)}{print $0}}' fl.txt>fll.txt
[root@linuxstudy fixlengthtest]# cat -A fll.txt
1|2|3|89$
a|b|c|li$
1|2|3|45  8$
a|b|c|deftl$
1||3|45678$
a|b|c|deftli$
1|2|3|456789$
a|b|c|deftli$
[root@linuxstudy fixlengthtest]# cat -A fl.txt
123    89$
abc    li$
12345  8$
abcdeftl$
1 345678$
abcdeftli$
123456789$
abcdeftli$
[root@linuxstudy fixlengthtest]# awk -v FIELDWIDTHS="1 1 1 6" -v OFS="|" '{for(i=1;i<=NF;i++){gsub(/^[[:blank:]]*/,"",$i);gsub(/[[:blank:]]*$/,"",$i)}{print $0}}' fl.txt
1|2|3|89
a|b|c|li
1|2|3|45  8
a|b|c|deftl
1||3|45678
a|b|c|deftli
1|2|3|456789
a|b|c|deftli
[root@linuxstudy fixlengthtest]#

你可能感兴趣的:(awk gsub)