美文网首页
awk提取某一行某一列

awk提取某一行某一列

作者: 不懒狮Blaise | 来源:发表于2017-10-16 13:19 被阅读0次

awk使用说明

1、打印文件的第一列(域)                 : awk '{print $1}' filename
2、打印文件的前两列(域)                 : awk '{print $1,$2}' filename
3、打印完第一列,然后打印第二列  : awk '{print $1 $2}' filename
4、打印文本文件的总行数                : awk 'END{print NR}' filename
5、打印文本第一行                          :awk 'NR==1{print}' filename
6、打印文本第二行第一列                :sed -n "2, 1p" filename | awk 'print $1'
  1. 原文档内容格式:
词组 拼音  次序
阿爸 a1'ba4  18137
阿昌族 a1'chang1'zu250849
阿斗 a1'dou3  42632
阿飞 a1'fei1  48603
阿富汗 a1'fu4'han43461
阿訇 a1'hong1  34432
阿拉伯数字 a1'la1'bo2'shu4'zi435937
阿拉伯语 a1'la1'bo2'yu330476
阿妈 a1'ma1  16220
阿门 a1'men2  47913
阿Q a1'qiu1  20845
阿司匹林 a1'si1'pi3'lin240294
阿嚏 a1'ti4  54643
  1. 共3列内容,现在只提取第一列词表,并存入另一文件:
awk '{print $1}' ./CH_word_ls.txt <strong>></strong> ./out.txt  

其中 ./CH_word_ls.txt是输入文件名

  1. 如果想提取前两列,只需
awk '{print $1,$2}' ./CH_word_ls.txt <strong>></strong> ./out.txt  
  1. 然后对文本进行去重并输出到文件CH_words:
sort out.txt | uniq > CH_words

相关文章

网友评论

      本文标题:awk提取某一行某一列

      本文链接:https://www.haomeiwen.com/subject/fhukuxtx.html