The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions ramky79 UNIX for Advanced & Expert Users 3 05-21-2008 05:13 PM
Help with regular expressions arushunter Shell Programming and Scripting 13 12-24-2006 12:31 AM
regular expressions jack1981 Shell Programming and Scripting 4 07-12-2006 03:10 PM
regular expressions in c++ szzz High Level Programming 2 10-06-2003 10:33 AM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 03:55 PM

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

Join Date: Jun 2006
Posts: 29
Regular Expressions

How can i create a regular expression which can detect a new line charcter followed by a special character say * and replace these both by a string of zero length?

Eg:
Input File san.txt

hello
hi
*User
Good
*Morning
Good
Bye


Applying sed command

sed 's/Reg.Expr/g' san.txt
--------------------------------------->

Desired output

hello
hiUser
GoodMorning
Good
Bye

What should be the value of Reg.Expr i.e. Regular Expression to get the desired output??


Please help
  #2 (permalink)  
Old 06-09-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
sed 's/^\*//s' filename
  #3 (permalink)  
Old 06-09-2006
sandeep_hi sandeep_hi is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 29
I tried that but it is not giving the desired output

$ sed 's/^\*//g' san.txt
hello
hi
User
Good
Morning
Good
Bye


Desired Output is
hello
hiUser
GoodMorning
Good
Bye
  #4 (permalink)  
Old 06-09-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
I don't know how to do that with sed, I guess. awk works:
Code:

awk 'BEGIN{ getline; printf "%s", $0}
    { if(substr($0,1,1)=="*"){
         printf "%s", substr($0,2)
      }
      else {
         printf "\n%s", $0
      }
    }    
     END{printf "\n"} 
     ' filename
  #5 (permalink)  
Old 06-09-2006
sandeep_hi sandeep_hi is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 29
Thank you so much...it worked for me.
I am a newbie to shell scripts and slowly working out my way. I have been trying this since two days but couldnt make out.



Thanks again

Last edited by sandeep_hi; 06-09-2006 at 08:44 AM..
  #6 (permalink)  
Old 06-11-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
What about this:
Code:
sed 'N;s/\n\*//;P;D;' san.txt
Regards,
Tayyab
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 01:30 AM.


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