Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-11-2012, 10:05 AM
|
#1
|
LQ Newbie
Registered: May 2012
Posts: 5
Rep: 
|
Creating a condensed table from a pre-existing table in putty
Hello,
I'm working with putty on Windows 7 professional and I'd like to know if there's a way to gather specific lines from a pre-existing table and make a new table with that information.
More specifically, I'd like the program to look at a specific column, say column N, and see if any of the rows in the column contain specific words (i.e. from this_is_what_i'm_looking_for, I'd like to to find all the rows in the colum that contain this_is), and print all these rows in a new table that I can save.
I can do this using Excel, but I'd like to know if there's a way to do it using putty.
Thank you.
|
|
|
05-11-2012, 10:17 AM
|
#2
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,349
Rep: 
|
It's not very clear what you're asking here (at least not to me).
Are you using putty to connect to a Linux system from Windows 7? What sort of "table" are we talking about here? A text file?
|
|
|
05-15-2012, 02:59 PM
|
#3
|
LQ Newbie
Registered: May 2012
Posts: 5
Original Poster
Rep: 
|
Hello,
I figured out what to do in order to make my program do what I want it to do:
vi (gets you to the VIM program)
e: filename.txt (opens up the text file you want to manipulate)
:%g!/searchwords/d (looks for the words you are searching for in your document, and deletes any row that doesn't contain this information)
:w newfilename.txt (saves the information left over (the info you are looking for) as a new text file)
So, let's say this is my newfilename.txt document:
1234 someinfo1 moreinfo1, 1235
1236 someinfo2 moreinfo2, 1238
1239 someinfo3 moreinfo3, 5793
and I have some other text file called othertextfile.txt that looks like this:
1235 someinfo4 moreinfo4
1238 someinfo5 moreinfo5
5793 someinfo6 moreinfo6
and I want my program to go through newfilename.txt and look at all the numbers found in the third column of the first file (1235, 1238, 5793) and output the corresponding 3rd column in the second file, for each one
i.e.
the third column of the first file has the numbers 1235, so it would find 1235 in the second file and output 1235 moreinfo4.
I'd like to continue using vi if possible
Thank you
|
|
|
05-16-2012, 11:07 AM
|
#4
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,349
Rep: 
|
It may be possible to do this in vim, but what you describe is really a job for join. In fact, this is pretty much exactly the kind of operation join was designed to perform:
Code:
join -1 4 -2 1 -o "1.4 2.3" newfilename.txt otherfile.txt
The parameters mean:
-1 4 -2 1: Compare the fourth field in the first file with the first field in the second file.
-o "1.4 2.3": Output the contents of the fourth field from the first file and the third field from the second file.
newfilename.txt: The name of the first file is "newfilename.txt"
otherfile.txt: The name of the second file is "otherfile.txt" If you want the results stored in a file rather that shown onscreen, just redirect the output to a file with the > operator ( > results.txt).
For this to work, both input files must be sorted by the columns you're comparing against. sort can to that for you.
|
|
|
All times are GMT -5. The time now is 08:23 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|