The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
strange behavior of find with xargs jerardfjay Shell Programming and Scripting 9 08-09-2007 09:06 AM
Very Strange Behavior for redirection cahook Shell Programming and Scripting 5 08-08-2007 12:32 PM
Strange Real Memory usage behavior Skyybugg AIX 5 05-31-2007 11:17 AM
Strange Behavior on COM2 Elwood51 UNIX for Dummies Questions & Answers 0 08-02-2006 04:31 PM
Strange behavior from 'read' statements. (ksh - but could be same on other shells) alexop Shell Programming and Scripting 5 05-02-2006 12:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2003
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
strange sed behavior

I have a file called products.kp which contains, for example,

12345678,1^M
87654321,2^M
13579123,3

when I run the command

cat products.kp| sed -f kp.sed

where kp.sed contains

s,^M,,

I get the output

12345678,1
87654321,2
13579123,3

so everything is ok.


However, when I run this command on another unix box, I get the output

12345678,1
87654321,2

ie. I don't get the last line returned.

has anyone any idea why? or a different way to do it in sed?

Thanks

ps. I'm using Sco and Bourne shell
  #2 (permalink)  
Old 06-12-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
If you have accurately described the situation, your version of sed has a bug. Complain to your vendor.

However, note that sed is line based. A line is a sequence of characters followed by a newline character. The last character of your file must be a newline character. If this is not the case, the results are undefined and both versions of sed are working correctly.
  #3 (permalink)  
Old 06-12-2003
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
Thanks,

the file does always have a missing ^M on the last line. Is there any way I can get around this?

To give you a brief outline, the suppliers of the package that produces this file for our system have done a new release which produces the file as described (whereas it used to have a ^M on every line).

On our system, which is released across 220 unix boxes, I run the 'sed -f kp.sed' command, so the only thing I can realistically change is the contents of kp.sed (maybe to append a ^M to every line then substitute it for '' ?)

or am I done for & will just have to wait for their fix to their system?
  #4 (permalink)  
Old 06-12-2003
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
I'm not really following you, but here are some comments that might clear up some confusion.

A control M in not a newline character. Control M's are not required in a line. If you have a text file that is missing the last newline character, you can append one with:
echo >> file

How many lines does "wc -l" find in your file?

To get rid of Control M's, you may have a program called dos2unix. You can also use "tr -d". And there are other solution that have been mentioned before as a substitute for dos2unix. You might try our search function since they have been mentioned before.
  #5 (permalink)  
Old 06-13-2003
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
I've sorted it now, I ended up using dtox & then echoing it to a file like you suggested. This sort of thing

>$1.okp
dtox $1.kp > $1.dtox
for line in `cat $1.dtox`
do
echo $line >> $1.okp
done

Have to release a patch over 220 boxes now though!
  #6 (permalink)  
Old 06-13-2003
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
Smile

Thanks for all your help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0