使用awk从文本文件中删除第一列

Del*_*fin 1 awk text sed

我有下一个文本文件:

Article_Title                                                                            1st_Author   Publication_Year    Language   Citations

Über die Theorie des Stoßes zwischen Atomen und elektrisch geladenen Teilchen            Fermi        1924                German     54
Zur Quantelung des idealen einatomigen Gases                                             Fermi        1926                German     333 
Eine statistische Methode zur Bestimmung einiger Eigenschaften des Atoms und ihre 
Anwendung auf die Theorie des periodi schen Systems der Elemente                         Fermi        1928                German     1833
Über die magnetischen Momente der Atomkerne                                              Fermi        1929                German     795
Über das Intensitätsverhältnis der Dublettkomponenten der Alkalien                       Fermi        1929                German     134
Über den Ramaneffekt des Kohlendioxyds                                                   Fermi        1931                German     594
Quantum Theory of Radiation                                                              Fermi        1932                English    951
Zur Theorie der Hyperfeinstruktur                                                        Fermi        1933                German     280
Possible Production of Elements of Atomic Number Higher than 92                          Fermi        1934                English    175
Versuch einer Theorie der ?-Strahlen                                                     Fermi        1934                German     525
Sopra lo Spostamento per Pressione delle Righe Elevate delle Serie Spettrali             Fermi        1934                Italian    901
Tentativo di una Teoria Dei Raggi ?                                                      Fermi        1934                Italian    475
On the Absorption and the Diffusion of Slow Neutrons                                     Almadi       1936                English    199
The Ionization Loss of Energy in Gases and in Condensed Materials                        Fermi        1940                English    710
The Capture of Negative Mesotrons in Matter                                              Fermi        1947                English    1156
Interference Phenomena of Slow Neutrons                                                  Fermi        1947                English    301
On the Origin of the Cosmic Radiation                                                    Fermi        1949                English    3309
Are Mesons Elementary Particles?                                                         Fermi        1949                English    498
Angular Distribution of the Pions Produced in High Energy Nuclear Collisions             Fermi        1951                English    324
Multiple Production of Pions in Nucleon-Nucleon Collisions at Cosmotron Energies         Fermi        1953                English    118
Run Code Online (Sandbox Code Playgroud)

第一列是科学论文的名称,第二列是作者的姓氏,第三列是出版年份,第四列是文章语言,第五列是引用次数。

我想将其转换成这样的东西:

  1924  54
  1926  333

  1928  1833
  1929  795
  1929  134
  1931  594
  1932  951
  1933  280
  1934  175
  1934  525
  1934  901
  1934  475
  1936  199
  1940  710
  1947  1156
  1947  301
  1949  3309
  1949  498
  1951  324
  1953  118
Run Code Online (Sandbox Code Playgroud)

因此,我需要删除第一列,第二列和第四列

问题是Article_Titles的列...如果Article标题是这样的:

辐射量子理论

我只需要运行下一个命令:

sed -i '1,2d' plotting_data.txt  # Removing First and second Line 
awk '{$1=$2=$4=""; print $0}' plotting_data.txt > tmp && mv tmp plotting_data.txt # Removing First, Second and Fourth Column
Run Code Online (Sandbox Code Playgroud)

问题是文章标题的单词之间有空格..我不知道如何告诉awk或sed删除该列..您能帮我吗?

我正在使用下一个awk版本:

mawk 1.3.3 Nov 1996,版权所有(C)Michael D. Brennan

编译限制:最大NF 32767 sprintf缓冲区2040

而且字段之间的空白都是空白字符

Ed *_*ton 5

假设样本中的空白都是空白字符,则可以在任何UNIX盒的任何shell中使用任何awk来工作:

$ awk 'NR==1{beg=index($0,$2)} NR>2{$0=substr($0,beg); print $2, $4}' file
1924 54
1926 333

1928 1833
1929 795
1929 134
1931 594
1932 951
1933 280
1934 175
1934 525
1934 901
1934 475
1936 199
1940 710
1947 1156
1947 301
1949 3309
1949 498
1951 324
1953 118
Run Code Online (Sandbox Code Playgroud)

  • 好吧,这点头。与`BEGIN {FIELDWIDTHS =“ 89 13 20 11 9”} ...相比,它更漂亮,并且对GNU的依赖更少。 (2认同)