Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

for eg. input :

// copyright

package com.base

import com.base
import com.base
...

i want to replace the pattern "// copyright\n\n^package.*" with another string

i'm trying to do using

sed -e 's/.,^package/$(anotherString)/g' $text 
share|improve this question
    
How many empty lines between // copyright and package ... ? One or two ? Your example has one empty line in between but you're saying you want to replace // copyright\n\npackage.* which means two empty lines in between... –  don_crissti Apr 16 at 17:18

1 Answer 1

Using sed

Here is a sed solution:

$ sed '\|// copyright|,\|^package|{s/^package/Something\nElse/p;d}' file
Something
Else com.base

import com.base
import com.base
...

Did you want to remove all of the original package line? If so, just a minor change is needed:

$ sed '\|// copyright|,\|^package|{s/^package.*/Something\nElse/p;d}' file
Something
Else

import com.base
import com.base
...

Using awk

$ awk '/^\/\/ copyright/,/^package/{if (/^package/) print "Something\nElse"; next} 1' file
Something
Else

import com.base
import com.base
...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.