Linux

將數據格式化成excel

  • February 1, 2021

我有大量以下格式的數據作為 txt 文件。如您所見,每一行都有標題,然後是路徑。這裡需要的是,我需要數據在 excel 中彼此相鄰出現 - 例如標題:路徑:

有人可以幫忙解決這個問題嗎?

目前結果

Title:Projects and Ideas
Path:/content/en_us/
Title:buying-guide
Path:/content/en_us/buying-guide
Title:Choose Exterior Paint Colors
Path:/content/en_us/buying-guide/choose-exterior-paint-colors
Title:Water Softener Buying Guide
Path:/content/en_us/buying-guide/water-softener-buying-guide
Title:Presentation Page
Path:/content/en_us/buying-guide/presentation-page

預期結果

Title:Projects and Ideas       Path:/content/en_us/
Title:buying-guide        Path:/content/en_us/buying-guide
Title:Choose Exterior Paint Colors Path:/content/en_us/buyingguide/choose
Title:Water Softener Buying Guide  Path:/content/en_us/buying-guide/water
Title:Presentation Page      Path:/content/en_us/buying-guide/presentation-page

我假設您希望將文件選項卡分開,以便您可以將其粘貼為表格。所以你可以做這樣的事情:

$ sed 'N;s/\n\(Path.*\)$/\t\1/' file
Title:Projects and Ideas    Path:/content/en_us/
Title:buying-guide  Path:/content/en_us/buying-guide
Title:Choose Exterior Paint Colors  Path:/content/en_us/buying-guide/choose-exterior-paint-colors
Title:Water Softener Buying Guide   Path:/content/en_us/buying-guide/water-softener-buying-guide
Title:Presentation Page Path:/content/en_us/buying-guide/presentation-page

Excel 不是 Unix/Linux 的主題,但同樣的問題可以應用於 Linux 可用的辦公軟體,如 LibreOfiice Calc,因此我的回答。

引用自:https://unix.stackexchange.com/questions/632023