![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regular Expressions | ramky79 | UNIX for Advanced & Expert Users | 3 | 05-21-2008 02:13 PM |
| Help with regular expressions | arushunter | Shell Programming and Scripting | 13 | 12-23-2006 09:31 PM |
| regular expressions | jack1981 | Shell Programming and Scripting | 4 | 07-12-2006 12:10 PM |
| regular expressions in c++ | szzz | High Level Programming | 2 | 10-06-2003 07:33 AM |
| Regular Expressions | AresMedia | Shell Programming and Scripting | 1 | 08-22-2002 12:55 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
sed 's/^\*//s' filename |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 05:44 AM. |
|
#6
|
||||
|
||||
|
What about this:
Code:
sed 'N;s/\n\*//;P;D;' san.txt Tayyab |
|
#7
|
|||
|
|||
|
Code:
BEGIN {lastString="";}
{ curStr=$0;
if (substr(curStr,1,1)=="*") {
len = length(lastString);
print substr(lastString,1,len) substr(curStr,2);
}else{
print substr(curStr,1)
}
lastString = curStr;
}
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|