- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: paste two files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:27 AM
02-19-2001 03:27 AM
Thanks to these forums I have found that I can merge two 1 column files into one 2 column file but using the 'paste' command..
My question is, is there anyway of matching the lines up?
so for instance, if I have two columns:
line1 line1
line2 line2
line3 line4
line4 line5
line5
Is there anyway I can get it to paste them together as:
line1 line1
line2 line2
line3
line4 line4
line5 line5
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:34 AM
02-19-2001 03:34 AM
Re: paste two files
What criterion would you use to decide whether or not a line in file1 matche a line in file2??
Bye,
Rik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:35 AM
02-19-2001 03:35 AM
Re: paste two files
If your two files have a common field, then you could ude the 'join' command.
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:37 AM
02-19-2001 03:37 AM
Re: paste two files
It must be identical...
say it's a list of hostname on systems... I want to ensure no hosts are missing from one and not in the other.. unfortunatly no file is the master.. some hosts are in one, and not in another and vice versa..
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:38 AM
02-19-2001 03:38 AM
Re: paste two files
In that case, I woulkd use the comm command to identify the differences between two (sorted) files.
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:48 AM
02-19-2001 03:48 AM
Re: paste two files
If you want to keep just one instance of every line, you could use:
cat file1 file2 | sort -u > file3
This would create a file, superset of file1 and file2 without duplicate entries.
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 03:59 AM
02-19-2001 03:59 AM
Re: paste two files
thanks, 'comm' is good, but I would really like to just match the lines and output to a new file with 2 columns.
So for instance...
If there's a host called "machine1" in file 1, but not in file 2, just print it on one line, however if there is a host called "machine2" in file1 AND file2 then print them next to each other..
basically I've sorted both lists in telephone directory order using 'sort -d' and would now just like to align matching entries against each other...
hmm... maybe it's not possible without a big script!
thanks anyway.. points on way!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 04:18 AM
02-19-2001 04:18 AM
Re: paste two files
If you would like some help let me know and I will help or even write it for you. (I don't have a lot to do right now).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 04:24 AM
02-19-2001 04:24 AM
Re: paste two files
If you could put together a little script..
I'd be interested to see how it's done.
Nik
[why argue with someone who offering to write a script for you?] :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 04:47 AM
02-19-2001 04:47 AM
Re: paste two files
Here (attached to ths post - click on the papar-clip) is a little script that does what you asked. Mind though, it does not do anything when a line in in file2 and not in file1 (but you didn't ask it, did you?)
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 04:48 AM
02-19-2001 04:48 AM
Re: paste two files
This time the attachment is included!!!
Here (attached to ths post - click on the papar-clip) is a little script that does what you asked. Mind though, it does not do anything when a line in in file2 and not in file1 (but you didn't ask it, did you?)
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 04:50 AM
02-19-2001 04:50 AM
Re: paste two files
Do you need a file to be produced as you have indercated above
or
would yout like to scripts to say that "hosname is in file1 but not 2" etc
or
if the hostname is not in file2 but is in file 1 the add it to file 2
the choice is yours :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 05:07 AM
02-19-2001 05:07 AM
Re: paste two files
If I could just get a file created with the two columns...
if it's only in file1, create the entry on one line on the left, if it's only in file2 then create the entry on one line on the right..
if it's in both, create both entrys left and right..
machine1
machine2
machine3 machine3
machine4
machine5
hope this makes sense!
thanks,
Nik
Rik: I'm trying your script now.. I might be able to adjust it to get results mentioned above? thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 05:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 05:50 AM
02-19-2001 05:50 AM
Re: paste two files
That's brilliant! But it won't stop!
Tried (( iContinue == FALSE )) instead of single = but no luck...
Nik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 05:58 AM
02-19-2001 05:58 AM
Re: paste two files
You're right.
It doesn't stop (except when to files have equal number of lines -- incidentally the way I tested it). Let me have a look, and I'll post a correction if OK.
Bye,
Rik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 05:59 AM
02-19-2001 05:59 AM
Re: paste two files
BTW, thanks for making me a Wizard!!
Bye.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 06:00 AM
02-19-2001 06:00 AM
Re: paste two files
Try this one as well
It a bit bigger than it 10 - 20 lines but it does it in a way that the files stay sorted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 06:06 AM
02-19-2001 06:06 AM
Re: paste two files
It does finish now!! Even when different number of lines in the files. And it still works with equal number of lines in the input files.
Bye,
Rik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2001 06:09 AM
02-19-2001 06:09 AM
Re: paste two files
Combining 'comm' and 'sed' will do the job.
comm file1 file2 | sed 's/\(
Replace the '
Best regards,
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2001 07:28 AM
02-20-2001 07:28 AM