LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-01-2017, 03:25 PM   #1
Sayantan1986
LQ Newbie
 
Registered: Aug 2017
Posts: 1

Rep: Reputation: Disabled
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
 
Old 08-01-2017, 03:31 PM   #2
TheEzekielProject
Member
 
Registered: Dec 2016
Distribution: arch
Posts: 668

Rep: Reputation: 190Reputation: 190
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
 
1 members found this post helpful.
Old 08-01-2017, 05:09 PM   #3
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,521

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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.
 
Old 08-01-2017, 07:16 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

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

jlinkels
 
Old 08-01-2017, 09:50 PM   #5
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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!!!

Last edited by !!!; 08-01-2017 at 10:05 PM.
 
1 members found this post helpful.
Old 08-02-2017, 07:10 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Quote:
Originally Posted by Sayantan1986 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
sed works on multiple lines but doesn't work on a single line monsteriname Programming 4 10-03-2012 02:23 AM
grep multiple words any order (AND, not OR) single line, from many files cedardoc Linux - Newbie 7 07-29-2010 10:23 AM
SED how to find multiple patterns on a single line yaazz Programming 9 07-31-2009 04:20 AM
combining multiple sed operations into a single command kushalkoolwal Programming 3 09-16-2008 05:58 PM
sed help, replacing a letter with a word GridX Linux - Newbie 1 09-24-2003 10:21 AM

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

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