LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Other *NIX
User Name
Password
Other *NIX This forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.

Notices

Reply
 
Search this Thread
Old 07-26-2007, 11:36 AM   #1
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 206Reputation: 206Reputation: 206
HP-UX newline character with sed


On GNU/Linux:
Code:
echo "absolut balogne." | sed "s/\ /\n/"
absolut
balogne.
On HP-UX:
Code:
echo "absolut balogne." | sed "s/\ /\n/"
absolutnbalogne.
Why doesn't it appreciate my newline character, and what do I do so that I get the desired effect (a newline in the output) ?

Thank you!

- Jameson
 
Old 07-27-2007, 04:37 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I figured I'd try responding without having a good answer.

My guess is that since Linux does not have a true Bourne Shell then this may be a difference between the true Bourne Shell and bash.

I would look for a common syntax for the command. For instance the following code is different than yours and it works on Linux. I don't have an HP-UX machine to test it on.
Code:
echo "absolut balogne." | sed "s/ /\n/"

Last edited by stress_junkie; 07-27-2007 at 04:38 PM.
 
Old 07-27-2007, 04:54 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
From the sed manpage (on a Mac):
Code:
Sed Regular Expressions
     The regular expressions used in sed, by default, are basic regular
     expressions (BREs, see re_format(7) for more information), but extended
     (modern) regular expressions can be used instead if the -E flag is given.
     In addition, sed has the following two additions to regular expressions:

     1.   In a context address, any character other than a backslash (``\'')
          or newline character may be used to delimit the regular expression.
          Also, putting a backslash character before the delimiting character
          causes the character to be treated literally.  For example, in the
          context address \xabc\xdefx, the RE delimiter is an ``x'' and the
          second ``x'' stands for itself, so that the regular expression is
          ``abcxdef''.

     2.   The escape sequence \n matches a newline character embedded in the
          pattern space.  You can't, however, use a literal newline character
          in an address or in the substitute command.
Try your first example in Linux using single quotes or use a sed script. I'm not at my Linux computer now so I can't try it.

Last edited by jschiwal; 07-27-2007 at 05:04 PM.
 
Old 07-27-2007, 05:08 PM   #4
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 206Reputation: 206Reputation: 206
stress_junkie -
Code:
hp-ux-on-bash-3.00$ echo "asbolut balogne." | sed "s/ /\n/"
asbolutnbalogne.
same stuff :-(
--
Quote:
Try your first example in Linux using single quotes
Yea, that usually works pretty good.

Code:
/home/jameson% exec /bin/bash
bash-3.00$ echo 'absolut balgogne.' | sed 's/\ /\n/'
absolutnbalgogne.
bash-3.00$ echo 'absolut balgogne.' | sed 's/ /\n/'
absolutnbalgogne.
makes no different on this ux box though :-/

Last edited by jhwilliams; 07-27-2007 at 05:12 PM.
 
Old 07-27-2007, 05:31 PM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The second example is using Linux, isn't it? It is behaving now the same as the the UX example did. I think that the "\n" is being changed to an actual return character before being read in by sed.
 
Old 07-27-2007, 05:43 PM   #6
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
OK, I tried it both ways in Linux. A newline was inserted. The difference is in the sed command itself. The paragraphs I quoted don't exist in the GNU sed manpage.
 
Old 07-27-2007, 07:57 PM   #7
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 206Reputation: 206Reputation: 206
Quote:
The second example is using Linux, isn't it?
No, sorry. I should have made that clear as in the first example. All of the commands in my previous post were on UX.
 
Old 08-06-2007, 03:21 PM   #8
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,189

Rep: Reputation: 105Reputation: 105
Solaris treats the \n in sed the same as HP/UX.

I learned sed and have always used it as an editor that works within individual lines within files. ^ and $ delimit the beginning and end of lines; but, for example, 's/^18//g' just removes the 18 from the beginning of the line, it does not remove the beginning of the line.

The Gnu/Linux example is probably an extension of the tradional functionality.

I just jump to other tools when one doesn't quite do it -- grep, tr, sed, awk, sort, uniq, etc. and then on to perl snippets. Although I agree it can be annoying when a really simple solution turns out not to be.
 
Old 08-06-2007, 05:13 PM   #9
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Original Poster
Rep: Reputation: 206Reputation: 206Reputation: 206
I have embarrasing news to report. The whole time I said "HP-UX," I was actually on an IRIX6 machine. (blushes)
 
  


Reply

Tags
gnu, hp, newline, sed


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 insert newline character jhwilliams Linux - Software 6 06-08-2007 03:13 PM
Sed remove trailing newline nc3b Programming 19 02-23-2007 03:13 AM
sed and newline problem Swift&Smart Slackware 3 08-15-2006 06:32 AM
SED newline usage question -- I think sadarax Linux - General 3 02-18-2006 11:50 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 06:20 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration