LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2009, 02:57 AM   #1
sysslack
Member
 
Registered: Feb 2006
Posts: 69

Rep: Reputation: 15
sed special


Hi!

I have seen good documentation on internet for sed but nothing for this special issue

How to match a word in a sentence like this
Can you use sed for this?
Hello how are you
(2 spaces between words)

to

Hello how are you
(1 space between words)

Observe the spaces should be only between words not between characters!

Last edited by sysslack; 05-06-2009 at 03:49 AM.
 
Old 05-06-2009, 03:14 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Can you explain your last sentence (only between words not between characters)?

Is this what you really want (by your last rule):
Code:
How  do  I  use  sed

becomes

How do  I  use sed
If all multiple spaces should be changes to 1 space (ignoring your last 'rule'):

sed 's/ [ ]*/ /g' infile

Hope this helps.
 
Old 05-06-2009, 03:18 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
# more file
Hello  how     are     you
# awk '$1=$1' file
Hello how are you
 
Old 05-06-2009, 04:01 AM   #4
sysslack
Member
 
Registered: Feb 2006
Posts: 69

Original Poster
Rep: Reputation: 15
Thank you ghostdog74
This was what I wanted. I have forgot have you put your code in code tags
:-)
 
  


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
block special and character special files s_shenbaga Linux - Newbie 4 06-23-2015 02:16 AM
Help w/ sed parsing special characters clem_c_rock General 8 08-31-2007 04:06 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
using sed to insert lines with special characters disorderly Linux - Software 26 04-20-2006 05:30 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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