将数据格式化为 Excel

将数据格式化为 Excel

我有大量以下格式的数据作为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

答案1

我假设您希望将文件选项卡分开,以便可以将其粘贴为表格。所以你可以这样做:

$ 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,因此我的答案。

相关内容