LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 02-16-2017, 07:36 AM   #1
ryan133
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Rep: Reputation: Disabled
help please new to linux


hello, i have a question. im working on an assignment where i have a file1 and a file2

file1
name, ryan
address, 1212
country, canada

file2
car, chevy
truck, ford
van, honda

i want to create a file3 only showing
ryan
1212
chevy

i know i have to use copy and paste but i cannot figure out the command

Last edited by ryan133; 02-16-2017 at 07:38 AM.
 
Old 02-16-2017, 07:54 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Welcome. We can't do homework for you but we can point in the right direction when you get stuck. Which commands have you tried?

If your data is in columns you can read the manual pages for join or uniq, you will find a hint in the "see also" section.

Code:
man join
man uniq
Though you might need to use sort on your data first.

Edit: never mind. I misread the data and you'll probably need another way to merge. Which ways have you tried besides pasting?

Last edited by Turbocapitalist; 02-16-2017 at 07:56 AM.
 
2 members found this post helpful.
Old 02-16-2017, 08:16 AM   #3
ryan133
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
i think im supose to use cut but not 100% sure ive been trying cut -f but not working
 
Old 02-16-2017, 08:19 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Ok. Read the page for cut

Code:
man cut
In addition to -f, the option you probably want may be -d, which will tell it how to identify the separator between the columns.

However, before you try that, how are you supposed to know which data to extract? What did the assignment or the teacher say about that?
 
Old 02-16-2017, 08:33 AM   #5
ryan133
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
this is what it says to do
Use the appropriate commands to create a file from the two created above containing the student first name, last name street, city and Postal Code

i changed the what it looked like on here but thats what it says have to create a 3rd file containing just few words for file 1 and 2
 
Old 02-16-2017, 08:44 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Hmm. Those instructions look incomplete. How should you know that 'chevy' is associated with 'ryan' in the two files?
 
1 members found this post helpful.
Old 02-16-2017, 08:51 AM   #7
ryan133
LQ Newbie
 
Registered: Feb 2017
Posts: 4

Original Poster
Rep: Reputation: Disabled
Create a file of about 10 records containing the following data (you create the values) separated by commas:
Student id
First name
Last name
Age
Phone number




Create a file of about 10 records containing the following data (you create the values) separated by commas:

Student id
Street
City
Postal code

Use the appropriate commands to create a file from the two created above containing the student first name, last name street, city and Postal Code

thats it
 
Old 02-16-2017, 08:57 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Oh. I would interpret those such that each set of data be listed in rows.

Code:
Student id, First name, Last name, Age, Phone number
1234, tommy, tutone, 23, 867-5309
4567, bon, scott, 24, 362-436
and so on. If you do it like that, then you can use cut
 
1 members found this post helpful.
Old 02-16-2017, 09:02 AM   #9
JeremyBoden
Senior Member
 
Registered: Nov 2011
Location: London, UK
Distribution: Debian
Posts: 1,947

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Why not just get yourself a database with "rows" in it?
 
Old 02-16-2017, 09:12 AM   #10
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Another good example how the more accurate the information you provide, the easier it is to get assistance
 
Old 02-16-2017, 03:37 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by ryan133 View Post
Create a file of about 10 records containing the following data (you create the values) separated by commas:
Student id
First name
Last name
Age
Phone number




Create a file of about 10 records containing the following data (you create the values) separated by commas:

Student id
Street
City
Postal code

Use the appropriate commands to create a file from the two created above containing the student first name, last name street, city and Postal Code

thats it
Great...so go do it. We aren't going to do your homework for you, as has been told to you previously. We will ALWAYS be happy to help you if you're stuck, but so far, you've posted one command, haven't read the man page for it, and posted a follow up question with no effort shown of your own.

Post what YOU, PERSONALLY have written/done/tried, and tell us what you're confused about. We can explain man pages, give you examples, etc., but we aren't going to give you a handout.
 
Old 02-17-2017, 06:42 AM   #12
techchamp
LQ Newbie
 
Registered: Feb 2017
Posts: 2

Rep: Reputation: Disabled
I am posting the direct answer as this is for an assignment and not an enterprise activity.

cat file1 | awk '{print " "$2}' |sed 's/,/ /g' |head -2 >file0;cat file2 | awk '{print " "$2}' |sed 's/,/ /g' |head -1 >>file0;cat file0

Thanks,
Techchamp - Linux
 
Old 02-17-2017, 06:45 AM   #13
techchamp
LQ Newbie
 
Registered: Feb 2017
Posts: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by techchamp View Post
I am posting the direct answer as this is for an assignment and not an enterprise activity.

cat file1 | awk '{print " "$2}' |sed 's/,/ /g' |head -2 >file0;cat file2 | awk '{print " "$2}' |sed 's/,/ /g' |head -1 >>file0;cat file0

Thanks,
Techchamp - Linux
[-- advertising link removed by moderator -- ]

Last edited by rtmistler; 02-17-2017 at 08:26 AM.
 
Old 02-17-2017, 08:19 AM   #14
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by techchamp View Post
I am posting the direct answer as this is for an assignment and not an enterprise activity.
cat file1 | awk '{print " "$2}' |sed 's/,/ /g' |head -2 >file0;cat file2 | awk '{print " "$2}' |sed 's/,/ /g' |head -1 >>file0;cat file0
Congratulations; you've done someones homework for them, and they have learned absolutely nothing from the exercise. Read the LQ Rules about homework questions, and if you're going to post something like this, don't then follow it up to advertise your 'linux learning' blog, which is also against the LQ Rules about advertising.
 
Old 02-17-2017, 08:26 AM   #15
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
Also ... "students, that's what your instructor is there for."

The purpose is to give you exercises that you can, in fact, solve by yourself and then to help you succeed in doing them. In this way, you learn about the various command-line tools that you are being introduced to in the class, and you develop the mode of thought that lets you do things like this using them.

"Yeah, it's a little mind-blowing, especially at first." (One columnist wrote a series of articles called A Sip From the Fire-Hose.) But, that's how you learn it. You come to expect to feel like this for a little while – until you solve it, which you know how to do.

Last edited by sundialsvcs; 02-17-2017 at 08:28 AM.
 
  


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



LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:30 PM.

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