bash - 如何拆分一行但在 bash 中保留其余行?
问题描述
我有这个:
2018-08-18 1 2 0.335106 0.335106
2018-08-19 1 0.335106
2018-08-20 1 0.335106
我要这个:
2018-08-18 1 0.335106
2018-08-18 2 0.335106
2018-08-19 1 0.335106
2018-08-20 1 0.335106
最后,我也需要摆脱 1 和 2。
到目前为止,我只能摆脱 1 和 2,但是当我这样做时,结果是:
2018-08-18 2
2018-08-19 1 0.335106
2018-08-20 1 0.335106
感谢您的帮助。
现在,我有这个:
if [ $elt_btch | wc -w ] -gt 1 then
size_eout_rec=`$last_7th_day $elt_btch $filesiz`
awk '{
wrdcnt = (NF - 1)/2
for (i=1; i<=wrdcnt; i++)
print $1, $(i+1), $(i+1+wrdcnt) >> $size_out_arc
}' <<END
else if [ $elt_btch | wc -w ] -eq 1 then
echo $last_7th_day $elt_btch $filesiz >> $size_out_arc
fi
if
解决方案
一般解决方案:
awk '{
half = (NF - 1)/2
for (i=1; i<=half; i++)
print $1, $(i+1), $(i+1+half)
}' <<END
2018-08-18 1 2 0.335106 0.335106
2018-08-19 1 0.335106
2018-08-20 1 0.335106
1970-01-01 1 2 3 4 0.1 0.2 0.3 0.4
END
2018-08-18 1 0.335106
2018-08-18 2 0.335106
2018-08-19 1 0.335106
2018-08-20 1 0.335106
1970-01-01 1 0.1
1970-01-01 2 0.2
1970-01-01 3 0.3
1970-01-01 4 0.4
不确定您所说的“摆脱 1 和 2”是什么意思,但您可能想要
print $1, $(i+1+half)
省略打印第二列
推荐阅读
- javascript - 如何为 HERE Javascript API 设置 HERE Base Map Tiles API?
- c# - 为从 Excel 文件导入的每两列分配 ID
- javascript - 无需创建模型即可发布 2 个字符串的最简单方法
- java - Android 应用可以在手机上运行,但不能在 AVD 上运行
- c++ - 使用c头文件时,是否需要将“struct”放在c++中的struct实例前面?
- python - 使用 ATLAS/LAPACK 支持构建 numpy
- java - 我可以使用 Java xunit 测试用 C# 编码的应用程序吗?
- python - 如何从 json 值中抓取属性
- python - 通过文本行搜索的正确方法 re.findall() 和 re.search() 都不能完全工作
- asp.net-core - 如何从 Nuget 更新锁定包版本