LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-17-2018, 06:46 AM   #1
mikudo
Member
 
Registered: Aug 2018
Posts: 82

Rep: Reputation: Disabled
paste -n functionality


I am trying to merge two temp files, one with 2 columns and one with 1 column so that I get a file with 3 columns.

However, some of the columns in the second file are missing because a command is timing out.

I found an answer that I could use paste -n but this option is not in man pages in my system.

What are my options? How else could I do this?

edit: to be clear, i want to print the row with one of the columns blank not erase the row

1 2 3
3 4 5
6 7
8 9 10
11 12 13 etc

Last edited by mikudo; 09-17-2018 at 06:53 AM.
 
Old 09-17-2018, 07:03 AM   #2
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
paste seems to be a good solution.
What's the problem exactly with using:
Code:
paste file1 file2
?

Quote:
Originally Posted by mikudo View Post
to be clear, i want to print the row with one of the columns blank not erase the row
paste does not erase the row should a column be blank...

PS: I'm not aware of a "n" option

Last edited by l0f4r0; 09-17-2018 at 07:06 AM.
 
Old 09-17-2018, 07:05 AM   #3
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
<DUPLICATE post, sorry>

Last edited by l0f4r0; 09-17-2018 at 07:08 AM.
 
Old 09-17-2018, 07:06 AM   #4
mikudo
Member
 
Registered: Aug 2018
Posts: 82

Original Poster
Rep: Reputation: Disabled
What I am getting though from paste f1 f2

is disjointing

1 2 3
4 5 6
7 8 10
11 12 13

etc, it is so very close to being correct. i read elsewhere that paste -n would give me the skipped column rather than the shift but this is not in all version of paste. im reading on column, join, table, and just looking for what will do it.
 
Old 09-17-2018, 07:14 AM   #5
mikudo
Member
 
Registered: Aug 2018
Posts: 82

Original Poster
Rep: Reputation: Disabled
Link to OP then?
 
Old 09-17-2018, 07:18 AM   #6
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Quote:
Originally Posted by mikudo View Post
What I am getting though from paste f1 f2 is disjointing
Can you define "disjointing" please?
Sorry but I don't manage in understanding your situation with the examples provided. It's not quite easy to get it just by the expected result. Could you try one of the following:
  • provide a more meaningful example with extracted actual content (if not confidential)?
  • provide the first 5 lines of 2 bogus files to "paste"?
 
Old 09-17-2018, 07:27 AM   #7
mikudo
Member
 
Registered: Aug 2018
Posts: 82

Original Poster
Rep: Reputation: Disabled
Sure.

first column, number of counts from uniq -c

second column, string

third column, result of command run on string

file1.txt
5 124124
20 93945
14 19009
10 90413

file 2 (some executed commands return empty row because operation times out and no way around this, in this example C is missing)
A
B
D

I need as output:
5 124124 A
20 93945 B
14 19009 blank (or string indicating command failed)
10 90413 D

paste -n is suppose to give me the blank space but this isn't in all shells.
 
Old 09-17-2018, 07:39 AM   #8
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Okay, it's clearer now.
Actually, your main issue is that the timeout doesn't return an "empty row" as you write it but no row at all. So I cannot imagine how shell could know that a line is missing so it goes on with the next one.
Either there is some logic between lines from file2 so you can indicate to shell when an expected line is missing OR you should try to write an empty row (or whatever default text you wish) in case of timeout. This done, you could paste your files as desired.
 
Old 09-17-2018, 07:40 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by mikudo View Post
Sure.

first column, number of counts from uniq -c

second column, string

third column, result of command run on string

file1.txt
5 124124
20 93945
14 19009
10 90413

file 2 (some executed commands return empty row because operation times out and no way around this, in this example C is missing)
A
B
D

I need as output:
5 124124 A
20 93945 B
14 19009 blank (or string indicating command failed)
10 90413 D

paste -n is suppose to give me the blank space but this isn't in all shells.
How is any join technique going to know, in this example, whether the third row in file 2 is in fact the third row (with the fourth being missed out) or the fourth row (with the third being missed out)?

P.S. Can you please use CODE tags (see https://www.linuxquestions.org/quest...og.php?b=36313) for your output.

Last edited by hydrurga; 09-17-2018 at 07:42 AM.
 
Old 09-17-2018, 07:46 AM   #10
mikudo
Member
 
Registered: Aug 2018
Posts: 82

Original Poster
Rep: Reputation: Disabled
This is helpful thank you. I will use code tags in the future.

I will have to, ugh, put in more logic lol to make sure that there is something in the row to match the other rows.

Gosh this simple script got complicated fast. I guess that is pretty normal that dealing with something like this will double the size and complexity of the script.
 
Old 09-17-2018, 07:54 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
People are correct, the paste command will not intelligently determine what lines to skip from file2. You'll have to figure out a way to match the file2 lines with file1 if you wish to use paste. The command description states this:
Quote:
Write lines consisting of the sequentially corresponding lines from each file
The key term is "sequentially corresponding lines"

EDIT: Sounds like you already got that point from the earlier posts.

Last edited by rtmistler; 09-17-2018 at 07:55 AM.
 
Old 09-17-2018, 07:55 AM   #12
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by mikudo View Post
This is helpful thank you. I will use code tags in the future.

I will have to, ugh, put in more logic lol to make sure that there is something in the row to match the other rows.

Gosh this simple script got complicated fast. I guess that is pretty normal that dealing with something like this will double the size and complexity of the script.
If file2 were to have a blank line (simply a LF) for each failed command rather than no line at all then that could work.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Preventing the screen copy and paste error on first paste slackartist Slackware 0 04-03-2016 06:48 PM
[SOLVED] parcellite can't 1) paste all; 2) Disable paste history display andrew.comly Linux - General 2 03-03-2015 08:53 PM
Right click paste instead of scroll wheel paste Jman-NZ Linux - Newbie 2 03-10-2013 05:57 PM
[SOLVED] rm and mv Functionality cin_ Linux - General 3 03-26-2012 06:58 PM
thinkpad T42 middle button - paste functionality primorec Linux - Laptop and Netbook 0 12-19-2005 02:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration