Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to interlace text files? [Solved]

Off-Topic discussions about science, technology, and non Debian specific topics.
Post Reply
Message
Author
CwF
Global Moderator
Global Moderator
Posts: 2679
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 196 times

How to interlace text files? [Solved]

#1 Post by CwF »

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.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: How to interlace text files?

#2 Post by Head_on_a_Stick »

Try paste(1) with a newline as the delimiter.
deadbang

CwF
Global Moderator
Global Moderator
Posts: 2679
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 196 times

Re: How to interlace text files?

#3 Post by CwF »

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...

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: How to interlace text files?

#4 Post by Head_on_a_Stick »

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 :)
deadbang

CwF
Global Moderator
Global Moderator
Posts: 2679
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 196 times

Re: How to interlace text files?

#5 Post by CwF »

Head_on_a_Stick wrote:Works for me :)
There it is!
Thanks, this will ease the required manual edit.

User avatar
sunrat
Administrator
Administrator
Posts: 6462
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 472 times

Re: How to interlace text files? [Solved]

#6 Post by sunrat »

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!

Post Reply