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
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 07:10 AM
SSH Problem auth problem budrito UNIX for Advanced & Expert Users 1 03-17-2004 07:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 12-12-2005
Registered User
 

Join Date: Apr 2005
Posts: 42
sed problem

Hi All,


I am having a text file say xyz which I convert into a file such that all the lines in that xyz file should have a “ on both the side of each line and \r and \n


xyz which need to be converted:
=============================
*%EFILocal [pdl_postscript:postscript]
*%EFILocal [pdl_pcl:pcl]

*%EFILocal [pdl_pjl:pjl]
*%EFILocal [pdl_pdf:pdf]
*%EFILocal [pdl_passthru:passthru]
*%EFILocal [pdl_text:text]

================================

Converted file: say abc
============================
"*%EFILocal [pdl_postscript:postscript]\r\n"
"*%EFILocal [pdl_pcl:pcl]\r\n"
“\r\n”
"*%EFILocal [pdl_pjl:pjl]\r\n"
"*%EFILocal [pdl_pdf:pdf]\r\n"
"*%EFILocal [pdl_passthru:passthru]\r\n"
"*%EFILocal [pdl_text:text]\r\n"
“\r\n”
"*%EFILocal [pdl_tiff:tiff]\r\n"
"*%EFILocal [pdl_xwd:xwd]\r\n"

I use the sed utility and did the following:

cat xyz | sed -e 's/\(.*\)$/"\1\\r\\n"/' | tr -d "\r" > abc

But it is not helping for all the lines. For some lien it is working and for some line it is not working at all. For some line it is not feeding " in the begining of the line.

Regards
Gauri Agrawal

Last edited by Perderabo; 12-12-2005 at 03:55 AM. Reason: Disable smilies for readability
Reply With Quote
Forum Sponsor
  #2  
Old 12-12-2005
mona's Avatar
Registered User
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Your command should work. Can you give some cases in which your command is not working? Add the anchor symbol and try again

Code:
sed -e 's/^\(.*\)$/"\1\\r\\n"/' xyz | tr -d "\r"
Reply With Quote
  #3  
Old 12-12-2005
Registered User
 

Join Date: Apr 2005
Posts: 42
thanks for the quick reply

actuly the following the line
*%EFILocal [invisible_yes:S\x92]

but when copy past only this line put in anothe file and then run sed, it works..

Can u please tell me how to add the anchor symbol. I guess it might be the problem

Thanks & Regards
Gauri Agrawal
Reply With Quote
  #4  
Old 12-12-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Quote:
Originally Posted by mona
Code:
sed -e 's/^\(.*\)$/"\1\\r\\n"/' xyz | tr -d "\r"
Since you need to match everything, you can use the & construct.

Code:
sed -e 's_.*_"&\\r\\n"_g' xyz
Reply With Quote
  #5  
Old 12-12-2005
mona's Avatar
Registered User
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Quote:
Originally Posted by vino
Since you need to match everything, you can use the & construct.

Code:
sed -e 's_.*_"&\\r\\n"_g' xyz
Hi Gauri,

Could you please try Vino's solution. "^" is the anchor symbol which matches the pattern in the beginning of the line.

Code:
sed -e 's_.*_"&\\r\\n"_g' xyz
I don't think the global flag is required.
Reply With Quote
  #6  
Old 12-12-2005
Registered User
 

Join Date: Apr 2005
Posts: 42
Hi Vino,

It has worked...can you please explain me if time permit u otherwise i will try to understand by my own as at least i got the solution.

Thanks Again
Regards
Gauri
Reply With Quote
  #7  
Old 12-12-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Quote:
Originally Posted by mona
I don't think the global flag is required.
True.

Force of habit !
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0