gpt4 book ai didi

shell - 使用 shell 将一行/行从列转置到行

转载 作者:行者123 更新时间:2023-12-01 08:13:24 30 4
gpt4 key购买 nike

我想使用 unix 命令将 txt 文件中的一列数据转换为 csv 文件中的一行。

例子:

ApplChk1,
ApplChk2,
v_baseLoanAmountTI,
v_plannedClosingDateField,
downPaymentTI,

这是一个存在于txt文件中的列

我想在csv文件中输出如下内容

ApplChk1,ApplChk2,v_baseLoanAmountTI,v_plannedClosingDateField,downPaymentTI,

请告诉我怎么做。

提前致谢

最佳答案

如果这是一个单列,您想将其转换为行,那么有多种可能性:

tr -d '\n' < filename ; echo # option 1 OR
xargs echo -n < filename ; echo # option 2 (This option however, will shrink spaces & eat quotes) OR
while read x; do echo -n "$x" ; done < filename; echo # option 3

请告诉我们,对于多行情况,输入会是什么样子。

关于shell - 使用 shell 将一行/行从列转置到行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051362/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com