LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-11-2018, 03:18 AM   #16
amy441
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled

Yes guys, but I'm stuck that's why I'm asking for a little help. If you give me some hit then that would be appreciated.

Also, I'm able to solve all other assignments my own but just stuck with this one. :/

Last edited by amy441; 06-11-2018 at 03:19 AM.
 
Old 06-11-2018, 05:44 AM   #17
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
I gave you some tips, you need to brake it down into small steps and implement them one by one. You can also simplify the task first.
 
Old 06-11-2018, 09:41 AM   #18
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,726

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
A significant part of the challenge of the assignment to split city,state into two separate fields is that not all of the lines have fields containing city also include a state. (This is one of the reasons sed may not be the best solution)

pan64 has outlined a "plan of attack" that should work, but again, it's your work to do.
 
Old 06-11-2018, 10:06 AM   #19
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Is this the entire body of input text you need to contend with?
Quote:
Originally Posted by amy441 View Post
This is an output of cat abc.csv file command. This is actually a homework given by my teacher and he specifically mentioned to split the column using SED.

Year,Rank,Organization ID,Organization Name,Organization Location,Private Income,Total Assets,Service Expense,Fundraising Expense
2004,1,321092,Salvation Army,"Alexandria, Va.","$1,324,089,000","$3,039,922,000","$2,126,200,000","$123,791,000"
2004,2,321148,American Cancer Society,Atlanta,"$794,000,000","$836,295,000","$610,639,000","$188,150,000"
2004,3,321036,Gifts In Kind International,"Alexandria, Va.","$787,192,199","$790,561,819","$792,432,766","$167,242"
I feel you should consider visiting with your instructor and asking them what the full point of this assignment truly is.


You can edit a file using sed. You can also use tr, and awk. Each tool has benefits and some drawbacks.


Well understood that they told you to only use sed.



A HUGE concern for me is summarized here:
Quote:
,"Alexandria, Va.",
,Atlanta,
,"Alexandria, Va.",
They've been inconsistent twice with their text for this problem.


That middle term is not enclosed in quotations


It also does not contain a state.


If their intention was to have you stretch your mind to properly change the first and third terms solely using sed, that's one thing.


Is the whole point of their assignment to be able to contend with the first and third terms, as well as the second term?


Is there more input text you haven't shown by the way?

Are you supposed to fix the quotations around "Alexandria, VA" so that it becomes "Alexandria", "VA",?

Are you supposed to add quotations around Atlanta?

And as asked by another person, what are you supposed to do about that term missing the state?

Last edited by rtmistler; 06-11-2018 at 10:08 AM. Reason: Added more Q's
 
1 members found this post helpful.
Old 06-11-2018, 10:52 PM   #20
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748Reputation: 2748
I agree that sed is a poor choice of tool for this exercise. I would be looking at gawk.
 
Old 06-11-2018, 11:14 PM   #21
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,121

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Missing fields are simply consecutive commas in a CSV. It's not actually that hard to do the entire exercise in sed - doing it in one stanza gets interesting - but it is an exercise for the OP.
 
Old 06-12-2018, 01:49 AM   #22
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
in general a huge list of seds like this:
Code:
s/"Alexandria, Va.",/,"Alexandria", "Va."/
may work.
Who knows?
 
Old 06-12-2018, 01:42 PM   #23
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,726

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I've spent way more time in the bowels of csv files than I ever wanted to.

Just to clarify a couple of things:
  • The fields are separated by commas.
  • If the field contains a comma, then it is quoted.
So, in the second row, the lack of a comma and state is why that field is not quote

If the OP could save the data from the spreadsheet in a tab-delimited format, that would remove all the delimiting commas and the quotes from the data, which might help things some.
In any case, it's important to differentiate between commas that are delimiters and commas that are data, and why the quotes are there.
 
  


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] separate information with \1 \2 in sed vincix Linux - Newbie 12 05-02-2017 04:41 AM
How do I separate columns using sed Basse1 Programming 4 07-01-2010 12:54 PM
File name in separate column jeesun Linux - General 5 04-26-2010 05:27 AM
sed/awk group on first column Eddie Adams Linux - General 4 04-09-2009 10:23 AM
Sed column replacement. keysorsoze Programming 11 12-01-2008 09:50 AM

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

All times are GMT -5. The time now is 03:27 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