|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Replacing 2 lines by single line
Hi I have a file with below content : Code:
a b S I need to replace the lines which have a and b continuously by d. Code:
d S I have used the below code Code:
tr '\n' '#'<file|sed. 's/a#b/d/g's?|tr '#' '\n' where # is not occurring anywhere in the file.. Is there any other efficient way to do this? Thanks |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
what does -0 stand for?
|
|
#4
|
|||
|
|||
|
Code:
sed '/a/{$q; N; s/a\nb/d/;}'Regards, Alister |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Hi Alister
Could you please explain how it works |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
From http://perldoc.perl.org/perlrun.html: Code:
-0[octal/hexadecimal]
specifies the input record separator ($/ ) as an octal or hexadecimal number. If there are no digits, the null character is the separator.
Other switches may precede or follow the digits. For example, if you have a version of find which can print filenames terminated by
the null character, you can say this:
find . -name '*.orig' -print0 | perl -n0e unlink
The special value 00 will cause Perl to slurp files in paragraph mode. Any value 0400 or above will cause Perl to slurp files whole,
but by convention the value 0777 is the one normally used for this purpose.
You can also specify the separator character using
hexadecimal notation: -0xHHH..., where the H are valid hexadecimal digits. Unlike the octal form, this one may be used to specify
any Unicode character, even those beyond 0xFF. So if you really want a record separator of 0777, specify it as -0x1FF.
(This means that you cannot use the -x option with a directory name that consists of hexadecimal digits, or else Perl will think you have
specified a hex number to -0.) |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
i am curious how to make sed to interpret "\n"? the below is not working as expected: Code:
sed 's/a\nb/d/g' file |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| replacing multi lines with 1 line | Griffs_Revenge | Shell Programming and Scripting | 3 | 01-23-2012 07:54 PM |
| Multiple lines in a single column to be merged as a single line for a record | Bhuvaneswari | Shell Programming and Scripting | 1 | 08-11-2011 03:16 AM |
| Break lines up into single lines after each space in every line | lewk | Shell Programming and Scripting | 7 | 10-14-2009 09:33 AM |
| replacing multiple lines with single line | siba.s.nayak | Shell Programming and Scripting | 3 | 05-28-2008 02:43 AM |
| replacing first line or lines in a file | Terrible | UNIX for Advanced & Expert Users | 3 | 06-28-2006 08:23 PM |
|
|