Клубить два файла после каждых 12 строк в системе hp-ux

289
kiran

У меня есть два больших файла. Один файл содержит 0-12 часов данных, а другие содержат 13-23 часа данных. Я хочу объединить его в один файл с 23-0 часами для каждой комбинации.

ex : file1  abcdefg00 abcdefg01 abcdefg02 --------- --------- abcdefg12 pqrstuv00 --------- ---------  file2 :  abcdefg13 abcdefg14 --------- --------- abcdefg23 pqrstuv13 --------- --------- 

Есть ли способ, которым я могу слиться, как это. вывод должен быть как ниже

> abcdefg00 > abcdefg01 > abcdefg02 > --------- > --------- > abcdefg12 > abcdefg13 > abcdefg14 > --------- > --------- > abcdefg23 > pqrstuv00 > --------- > --------- > pqrstuv13 > --------- > --------- > pqrstuv23 

Спасибо заранее

1
Привет Киран, добро пожаловать на SuperUser. Зарегистрируйтесь и проверьте, работают ли ответы в вашем случае. Если нет, добавьте комментарий или [отредактируйте] свой пост. Hastur 8 лет назад 0

2 ответа на вопрос

0
Ira

If you are asking to append the two files, one after the other, but to also reverse the order of the lines, you can use either tail -r or tac as in

cat file1 file2 | tail -r 

or

cat file1 file2 | tac 

The -r option may not be available on HP-UX tail. The command tac is part of coreutils if you need to add it.

0
Hastur

You can try to use sort

sort -n -k1 f1.txt f2.txt > newfile 

from man sort you can read that sort

Writes sorted concatenation of all FILE(s) to standard output.

You may need to select the column used to sort (-k1) or to select a numbering sort -n.

If your files are not strictly ordered you should do a script that reads 12 lines alternatively from the first and the second file with two file descriptors [1],[2].

It can result in something similar to this one

#!/bin/bash while true do for ((i=1;i<=12;i++)); do read -r f1 <&3 && echo "$f1" || exit 1 done for ((i=1;i<=12;i++)); do read -r f2 <&4 && echo "$f2" || exit 2 done done 3<file1 4<file2 

Until is able to read it writes else it exit with different error value if from the 1st or the 2nd cycle.

Похожие вопросы