Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 使用bash将列和排序与条件组合起来_Linux_Bash - Fatal编程技术网

Linux 使用bash将列和排序与条件组合起来

Linux 使用bash将列和排序与条件组合起来,linux,bash,Linux,Bash,如何组合多个列(并生成引用列)并根据条件对数据进行排序(如果数据不足,将留下空格、逗号或制表符) 以下是输入: Column A 00-03 00-06 00-14 00-25 00-54 00-59 01-08 01-42 01-49 01-59 02-08 02-10 02-17 02-18 02-23 02-48 02-51 02-54 02-57 Column B 00-04 00-44 00-51 01-11 01-25 01-43 02-00 02-03 02-24 Column

如何组合多个列(并生成引用列)并根据条件对数据进行排序(如果数据不足,将留下空格、逗号或制表符)

以下是输入:

Column A
00-03
00-06
00-14
00-25
00-54
00-59
01-08
01-42
01-49
01-59
02-08
02-10
02-17
02-18
02-23
02-48
02-51
02-54
02-57

Column B
00-04
00-44
00-51
01-11
01-25
01-43
02-00
02-03
02-24

Column C
00-19
00-46
01-21
01-26
01-38
01-47
01-49
01-52
01-58
02-16
02-20
02-57
02-58
我尝试使用“粘贴-d”,“”,它可以合并所有列,但如果数据不够,则不会留下空行。是否有任何方法或工具可以合并列并根据条件对列进行排序

以下是我想要的输出:

Heading,ColumnA,ColumnB,ColumnC
00,00-03,00-04,00-19
00,00-06,00-44,00-46
00,00-14,00-51,
00,00-25,,
00,00-54,,
00,00-59,,
01,01-08,01-11,01-21
01,01-42,01-25,01-26
01,01-49,01-43,01-38
01,01-59,,01-47
01,,,01-49
01,,,01-52
01,,,01-58
02,02-08,02-00,02-16
02,02-10,02-03,02-20
02,02-17,02-24,02-57
02,02-18,,02-58
02,02-23,,
02,02-48,,
02,02-51,,
02,02-54,,
02,02-57,,

对于您的具体案例,这将是一个快速而肮脏的解决方案

此脚本需要3个名为a、b、c的文件以及您提供的数据

mkdir temp 
echo Heading,ColumnA,ColumnB,ColumnC
for i in 00 01 02 ; do 
    for j in a b c ; do 
        grep ^$i $j > temp/$i$j; 
    done
    seq 1  $(wc temp/$i* | head -n -1| sort -n | tail -1 | awk {'print $1'})| while read line; do
        echo $i >> temp/$i; 
    done
    paste -d',' temp/$i*;
done
rm -rf temp

由于这是一项非常具体的任务,我认为单用一个简单的标准工具无法解决它。我会写一个程序,明确地表达在这里要做什么。它可以在bash中完成,但在更通用的语言(Ruby、Perl、Python)中会更容易一些。您基本上需要并行管理3个输入流和一个输出流。