How to interlace text files? [Solved]

If it doesn't relate to Debian, but you still want to share it, please do it here

How to interlace text files? [Solved]

Postby CwF » 2021-01-20 01:37

Any easy way to take 2, maybe 3 text files and interlace them into a single file?
So line 1 from file 1 is line 1.
line 1 from file 2 is line 2.
line 2 from file 1 is line 3.
or line 1 from file 3 is line 3.
and so on, each file 80-90 lines, so I quickly loose focus!
Last edited by CwF on 2021-01-20 17:27, edited 1 time in total.
CwF
 
Posts: 925
Joined: 2018-06-20 15:16

Re: How to interlace text files?

Postby Head_on_a_Stick » 2021-01-20 05:14

Try paste(1) with a newline as the delimiter.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13241
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: How to interlace text files?

Postby CwF » 2021-01-20 15:15

Thank you! Close, but no cigar.
It won't alternate lines. I expected "-d '/n'" to do it, the result is line1file1/line1file2 on one line.
However "-d '#'" is close to my desired with line1file1#line1file2(#line1file3) on one line, and this result is usable.

That's safe and makes my manual edit easier. It seems a lost cause to avoid a manual edit since any logic I inject is foiled by 'stupid'.

I'm parsing dvb scan files and each line contains important info and 'text' that is entered by various employees of varied intelligence, for which parsing is impossible. I need to manually clean it no matter what.

Problem #2 is the files order is based on frequency and that relation changes too, meaning I need to move blocks of info, with no pre-logic I can think of possible since each change would be unique.

If anybody has had a particular TV not receive all channels I might be able to tell you why!
Maybe this useful naming!
Code: Select all
Presented by KCEC:581000000:8VSB:65:68:2
Presented by KCEC:581000000:8VSB:81:84:3
Presented by KCEC:581000000:8VSB:97:100:4

Or overlapping affiliates (I have a really good antenna!)
Code: Select all
MYS:177000000:8VSB:65:68:4
Laff:177000000:8VSB:81:84:5
......
MYS:569000000:8VSB:65:68:4
Laff:569000000:8VSB:81:84:5

Or total ambiguity
Code: Select all
[0002]:479000000:8VSB:65:68:2


Those errors barf on some devices. I can correct them, but maybe not automagically...
CwF
 
Posts: 925
Joined: 2018-06-20 15:16

Re: How to interlace text files?

Postby Head_on_a_Stick » 2021-01-20 15:18

CwF wrote:It won't alternate lines. I expected "-d '/n'" to do it

Try a backslash instead:
Code: Select all
~$ cat test{1,2}
1
2
3
4
5
one
two
three
four
five
~$ paste -d '\n' test{1,2}
1
one
2
two
3
three
4
four
5
five
~$

Works for me :)
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 13241
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: How to interlace text files?

Postby CwF » 2021-01-20 15:30

Head_on_a_Stick wrote:Works for me :)

There it is!
Thanks, this will ease the required manual edit.
CwF
 
Posts: 925
Joined: 2018-06-20 15:16

Re: How to interlace text files? [Solved]

Postby sunrat » 2021-01-20 21:25

That's really neat! Of course I'll never remember it if I ever need it, and if I write it down it will guarantee I never need it! :lol:
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!
User avatar
sunrat
 
Posts: 3402
Joined: 2006-08-29 09:12
Location: Melbourne, Australia


Return to Offtopic

Who is online

Users browsing this forum: No registered users and 11 guests

fashionable