Ãâ·Ñ×¢²á ²é¿´ÐÂÌû |

Chinaunix

  ƽ̨ ÂÛ̳ ²©¿Í ÎÄ¿â
×î½ü·ÃÎÊ°å¿é ·¢ÐÂÌû
²é¿´: 3645 | »Ø¸´: 7
´òÓ¡ ÉÏÒ»Ö÷Ìâ ÏÂÒ»Ö÷Ìâ

[ѧϰ·ÖÏí] ΪʲôҪʹÓÃ4¸öתÒå·û [¸´ÖÆÁ´½Ó]

ÂÛ̳»ÕÕÂ:
0
Ìøתµ½Ö¸¶¨Â¥²ã
1Â¥ [ÊÕ²Ø(0)] [±¨¸æ]
·¢±íÓÚ 2012-11-08 04:38 |Ö»¿´¸Ã×÷Õß |µ¹Ðòä¯ÀÀ
  1. test$ echo "a\b\c" | awk -F'\\\\' '{OFS="@"; print $1,$2,$3}'
  2. a@b@c
¸´ÖÆ´úÂë
×¢ÒâÉÏÃæ4¸ö\ÍâÃæÊǵ¥ÒýºÅ
ÏÂÃæµÄ´úÂë¿ÉÒÔʵÏÖÏàͬµÄЧ¹û£º
  1. test$ echo "a\b\c" | awk -F\\\\\\\\ '{OFS="@"; print $1,$2,$3}'
  2. a@b@c
¸´ÖÆ´úÂë
¼´8¸ö\ÍâÃæûÓÐÒýºÅ
ºÍ8¸ö\ÍâÃæÓÐË«ÒýºÅЧ¹ûÏàͬ£º
  1. test$ echo "a\b\c" | awk -F"\\\\\\\\" '{OFS="@"; print $1,$2,$3}'
  2. a@b@c
¸´ÖÆ´úÂë
ÎÒµÄÎÊÌâÊÇ£º
shellÖе¥ÒýºÅºÍË«ÒýºÅµÄÇø±ðÊǵ¥ÒýºÅ°ÑËùÓÐ×Ö·û¶¼¿´³ÉÆÕͨ×Ö·û£¬ËùÒÔ²»¶ÔתÒå·û½øÐÐתÒ壬ËùÒÔ´«µÝ¸øawkʱӦ¸ÃÊÇ4¸ö\£¬awkÔÙ½øÐÐתÒåÓ¦¸ÃÊÇ2¸ö\²Å¶Ô£¿µ«´ÓÉÏÃæ¿´awkÏÔʾ°Ñ·Ö¸ô·ûµ±³É1¸ö\£¬ÄÇ»¹ÓÐÒ»°ëµÄתÒå·û±»Ë­³ÔÁË£¿bash»¹ÊÇawk£¿

ÂÛ̳»ÕÕÂ:
0
2Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-20 11:16 |Ö»¿´¸Ã×÷Õß

ÂÛ̳»ÕÕÂ:
0
3Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-20 13:22 |Ö»¿´¸Ã×÷Õß
¶ÔÂ¥Ö÷µÄÃüÁîÐÐÀ´ËµÓ¦¸ÃûÓÐÕâô¸´ÔÓ°É£¿ÎÒÕâôÓõģº

root@Deb606:~/test# echo "a\b\c" |awk -F"\\" '{print $1 $2}'
ab
root@Deb606:~/test# echo "a\b\c" |awk -F'\\' '{print $1 $2}'
ab

¼òµ¥À´Ëµ£¬µ¥ÒýºÅºÍË«ÒýºÅÔÚÕâ¸ö³¡¾°ÖÐûÓÐÇø±ð£¬ÒòΪÒýºÅÖÐûÓбäÁ¿ÐèÒªÕ¹¿ª¡£¶øÇÒÁ½¸öback slash¾Í¹»ÁË£¬Ã»ÓбØÒª4¸ö°É£¿

¡¾Debian 6.0.6¡¿

ÂÛ̳»ÕÕÂ:
0
4Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-25 23:01 |Ö»¿´¸Ã×÷Õß
»Ø¸´ 3# sakulagi


Õâ¸ö²»ÊDZäÁ¿Õ¹²»Õ¹¿ªµÄÎÊÌ⣬¿´ÏÂÃæ
  1. git$ echo "\\"
  2. \
  3. git$ echo '\\'
  4. \\
¸´ÖÆ´úÂë
Ë«ÒýºÅÀï\±»µ±³ÉתÒå·ûËùÒÔ½á¹ûÊÇ1¸ö£¬¶øµ¥ÒýºÅÀïËùÓзûºÅ¶¼µ±³ÉÆÕͨ×Ö·ûËùÒÔûÓÐתÒ壬ËùÒÔÓÐ2¸ö

ʵ¼ÊÉϵ±Êǵ¥ÒýºÅµÄʱºò ÄãµÄÀý×ÓÀï1-4¸ö\½á¹û¶¼ÊÇÒ»ÑùµÄ
ÒòΪÊǵ¥ÒýºÅËùÒÔËùÓÐ×Ö·û¶¼Ó¦¸ÃÊÇÆÕͨ×Ö·û£¬¼´´«¸øAWKµÄÓ¦¸ÃÊÇ4¸ö£¬Ôõô»á¸ú´«1¸öÒ»ÑùÄØ£¿

¼ÙÈçÎÒÏÖÔÚÒª·Ö¸ô·ûÊÇ\n ÄÇô±ØÐëÒª4¸ö£¬ÆäËü¶¼²»ÐУº
  1. git$ echo "a\nb\nc" |awk -F'\\\\n' '{for(i=1;i<=NF;i++) print $i;}'
  2. a
  3. b
  4. c
¸´ÖÆ´úÂë
ÕâÓÖÔõô½âÊÍÄØ£¿

ÂÛ̳»ÕÕÂ:
0
5Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-25 23:05 |Ö»¿´¸Ã×÷Õß
»Ø¸´ 2# personball


ÄÇƪÌû×ÓÎÒ¿´Ã÷°×ÁË ÎÒÔ­À´¾ÍÊÇÄÇôÀí½âµÄ

µ«¶Ô½â¾öÕâ¸öÎÊÌâºÃÏñûʲôÓð¡

ÂÛ̳»ÕÕÂ:
0
6Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-27 09:03 |Ö»¿´¸Ã×÷Õß
±¾Ìû×îºóÓÉ sakulagi ÓÚ 2012-11-27 09:03 ±à¼­

±§Ç¸ÎÒ֮ǰûÓÐ˵ÍêÕû¡£¶ÔÓÚË«ÒýºÅµÄºÍµ¥ÒýºÅµÄÇø±ð£¬Ö÷Òª»¹ÊDZäÁ¿µÄÕ¹¿ª£¬ºÍ¼«ÉÙÊýÇé¿öÏÂÌØÊâ×Ö·ûÊÇ·ñ»á±»½âÊÍ¡£¶ÔÓÚ \ À´Ëµ£¬³ý·ÇÄãÊÇÓÃ\À´ÐÞÊÎÆäËûµÄquote, ±ÈÈç\, $, ' £¬"£¬·ñÔò»¹ÊDz»»áµ±³ÉתÒå·û£¬Ö»Êǵ±×öÆÕͨ×Ö·û´¦ÀíµÄ£¬¼´Ê¹ÊÇÔÚË«ÒýºÅÖС£

ÄãÊÔÊÔÖ´ÐеÄÃüÁîµÄÇ°°ë²¿·Ö£º

echo "a\nb\nc"

ºÍ

echo 'a\nb\nc'

µÄÖ´Ðнá¹ûÊÇÒ»ÑùµÄ¡£

ÔÚÄãµÄÃüÁîÀʵÄãÓÃ\nÕâÁ½¸ö×Ö·ûÔÚ×öawkµÄÓò·Ö¸ô·û¡£µ±Óò·Ö¸ô·ûÊǶàÓÚÒ»¸ö×Ö·ûµÄʱºò£¬awk»áÈÏΪÕâÊÇÒ»¸öreg-ex£¬´Ó½á¹û¿´Ã²ËÆ´¦ÀíÁËÁ½´Î¡£ÎÒû¿´¹ýÔ´´úÂ룬²»ºÃ˵¡£

ÖÁÓÚ1Â¥µÄÄǸöÀý×Ó¡£²»ÓÃ4¸ö\:

  1. [edward@vm-fedora17 ~]$ echo "a\b\c" | awk -F'\' '{OFS="@"; print $1,$2,$3}'
  2. a@b@c
¸´ÖÆ´úÂë

ÂÛ̳»ÕÕÂ:
0
7Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-27 20:45 |Ö»¿´¸Ã×÷Õß
»Ø¸´ 6# sakulagi


http://www.gnu.org/software/gawk ... ml#Escape-Sequences

Advanced Notes: Backslash Before Regular Characters

If you place a backslash in a string constant before something that is not one of the characters previously listed, POSIX awk purposely leaves what happens as undefined. There are two choices:

Strip the backslash out
This is what Brian Kernighan's awk and gawk both do. For example, "a\qc" is the same as "aqc". (Because this is such an easy bug both to introduce and to miss, gawk warns you about it.) Consider ¡®FS = "[ \t]+\|[ \t]+"¡¯ to use vertical bars surrounded by whitespace as the field separator. There should be two backslashes in the string: ¡®FS = "[ \t]+\\|[ \t]+"¡¯.)

Leave the backslash alone
Some other awk implementations do this. In such implementations, typing "a\qc" is the same as typing "a\\qc".


ÎÊÌâ¹Ø¼üÓ¦¸ÃÔÚ£ºÈç¹û\²»¿ÉÒÔ¸úºóÃæ×Ö·û¹¹³ÉÌØÊ⺬Ò壬ÄÇÓÐûÓÐ\ÊÇÒ»ÑùµÄ£¬±ÈÈ磺\xºÍxÊÇÒ»ÑùµÄ¡£

tmp$ echo "a\xb"|awk -F'\x' '{print $1 "#" $2 "\t" NF}'
a\#b        2
tmp$ echo "a\xb"|awk -F'x' '{print $1 "#" $2 "\t" NF}'
a\#b        2

ΪÁËÆ¥Åä"\x" ÖÁÉÙÒª3¸öתÒå·û¡£
µ«"\n"ÖÁÉÙÐèÒª4¸ö¿ÉÄܺÍ\n¾ßÓÐÌØÊ⺬ÒåÓйء£

ÂÛ̳»ÕÕÂ:
0
8Â¥ [±¨¸æ]
·¢±íÓÚ 2012-11-28 09:03 |Ö»¿´¸Ã×÷Õß
Äã˵µÄÓеÀÀí¡£ÎÒÒ²¸Ð¾õÓ¦¸ÃÊÇAWKµÄʵÏÖÖÐÓÐЩ¾ßÌåµÄ´¦Àí·½Ê½²»Í¬
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | ×¢²á

±¾°æ»ý·Ö¹æÔò ·¢±í»Ø¸´

  

±±¾©Ê¢ÍØÓÅѶÐÅÏ¢¼¼ÊõÓÐÏÞ¹«Ë¾. °æȨËùÓÐ ¾©ICP±¸16024965ºÅ-6 ±±¾©Êй«°²¾Öº£µí·Ö¾ÖÍø¼àÖÐÐı¸°¸±àºÅ£º11010802020122 niuxiaotong@pcpop.com 17352615567
δ³ÉÄê¾Ù±¨×¨Çø
Öйú»¥ÁªÍøЭ»á»áÔ±  ÁªÏµÎÒÃÇ£ºhuangweiwei@itpub.net
¸ÐлËùÓйØÐĺÍÖ§³Ö¹ýChinaUnixµÄÅóÓÑÃÇ ×ªÔر¾Õ¾ÄÚÈÝÇë×¢Ã÷Ô­×÷ÕßÃû¼°³ö´¦

Çå³ý Cookies - ChinaUnix - Archiver - WAP - TOP