LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Replacing multiple words with single word using SED (https://www.linuxquestions.org/questions/linux-newbie-8/replacing-multiple-words-with-single-word-using-sed-4175611074/)

Sayantan1986 08-01-2017 03:25 PM

Replacing multiple words with single word using SED
 
Hi Team,
I have a variable which stores some values separated by commas.

Requirement is to replace the comma separated values with 1 value globally using sed.

Comma separated values can be of n numbers.

Can you please suggest how we can achieve this.


Thanks

TheEzekielProject 08-01-2017 03:31 PM

What have you tried and where are you stuck? Show us the effort you have put in. You're unlikely to find someone that's going to code from scratch for you

AwesomeMachine 08-01-2017 05:09 PM

I think awk might work better than sed. If you have
Code:

1,2,3,4,5
and you want to extract $3, which is 3
Code:

$ awk -F , '{print $3}'
will do it.

jlinkels 08-01-2017 07:16 PM

The OP cannot use awk because his assignment requires he uses sed. It's homework.

jlinkels

!!! 08-01-2017 09:50 PM

Welcome to LQ. You will receive very useful "soft skills" for a successful career, in addition to tech help.
I see from your profile that you returned after post#2 gave you good "real world" advice.

Tell us about your Linux experience and distro/PC access, and desires/goals.
In case you have zero experince, I will give you a hint: web-search: man sed
Look for the 's' function/operator, and the 'g' modifier to it.

At least copy&paste here, what you see as the minimal relevant key info,
if not your attempt at how you would try to do your assignment.

Excuse this bit of "tough love": think of this: you are on your first day at work, to simply move boxes.
You ask the instructor to do it for you, so you will pass your first test.
Will things turn out well? Hopefully other future students will read this!!!
Edit: a helpful person hears you ask and jumps in and does it for you.
You fail, the school kicks you out, it goes on your record, you starve to death.
This now wll NOT happen!!! You WILL succeed!!! ... You're welcome;)

We DO want you to come back and post your first actual step, no matter what real attempt it is.
We enjoy guiding you, but doing ALL YOUR WORK FOR YOU would be a great dis-service to you!!!

Please come back!!! Linux is fun and valuable!!! ;)

rtmistler 08-02-2017 07:10 AM

Quote:

Originally Posted by Sayantan1986 (Post 5742850)
Hi Team,
I have a variable which stores some values separated by commas.

Requirement is to replace the comma separated values with 1 value globally using sed.

Comma separated values can be of n numbers.

Can you please suggest how we can achieve this.


Thanks

Hi Sayantan1986 and welcome to LQ,

LQ Welcome, there are some links in there how best to use and benefit by this site.

LQ Rules/Guidelines
Quote:

Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.


All times are GMT -5. The time now is 09:02 AM.