From owner-freebsd-questions@FreeBSD.ORG Fri May 29 13:00:30 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 589491065676 for ; Fri, 29 May 2009 13:00:30 +0000 (UTC) (envelope-from invalid.pointer@gmail.com) Received: from mail-qy0-f173.google.com (mail-qy0-f173.google.com [209.85.221.173]) by mx1.freebsd.org (Postfix) with ESMTP id 08C3D8FC24 for ; Fri, 29 May 2009 13:00:29 +0000 (UTC) (envelope-from invalid.pointer@gmail.com) Received: by qyk3 with SMTP id 3so8722685qyk.3 for ; Fri, 29 May 2009 06:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=4l3+EsXxyxypBw7P5Ez+qQfkPESmaAn0xH7AmqCY7pw=; b=m3saiCCRQYyUS7S//18bTdaFWfQRUfHsEzy3XK4jkwPjpJWScdJu4gyLEM0zhxtiiS UQbw+fxlVT0ncrjGz0R9A589gqSbDFCB7yGZG7f/nPMYYl3Hnzdh1OWD/Kaxhh8r9tQy hMOz2vapFXupwXT2Bgio93iVSzCIIy2mrDphs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=pPN7TRhe4cEe+HfWBex415NIXVsF6oe1fKcr7OgYYJ9ZWxSEcJ2y/8bOrof60mjFlg 2EdOxB6A7rE8/4zyV6Kla62Ix58N4uNmC0GxgF3xkZvGevh+NJkhNDeY5jDdLsm1+sv0 ZXgyVeoAcPwSsvUgoD5ogcfxzjywrueN7XgkM= Received: by 10.224.2.212 with SMTP id 20mr2639705qak.338.1243602029303; Fri, 29 May 2009 06:00:29 -0700 (PDT) Received: from ?152.144.218.148? ([203.92.44.179]) by mx.google.com with ESMTPS id 5sm1268946qwh.44.2009.05.29.06.00.25 (version=SSLv3 cipher=RC4-MD5); Fri, 29 May 2009 06:00:28 -0700 (PDT) Message-ID: <4A1FDC65.5040207@gmail.com> Date: Fri, 29 May 2009 18:30:21 +0530 From: Manish Jain User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: Paul Schmehl References: <4A1E8824.1020604@gmail.com> <81CA7451D4C324A373C6451B@utd65257.utdallas.edu> In-Reply-To: <81CA7451D4C324A373C6451B@utd65257.utdallas.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Roland Smith , FreeBSD Mailing List Subject: Re: Need sed to do something which sounds simple X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 May 2009 13:00:30 -0000 Paul Schmehl wrote: > --On Thursday, May 28, 2009 07:48:36 -0500 Manish Jain > wrote: > >> >> >> Hi, >> >> I need sed to do something which sounds simple, but I can't figure out >> the right command. All I need to do is insert a blank after a '}' at the >> end of a line if the next line begins immediately afterwards (i.e. with >> no blank line between). >> >> //abc.cpp : >> int myclass::fx(int * arg) >> { >> if(! (isValid())) >> { >> return -1; >> } >> return ptr->fx(arg); >> } >> >> //what-i-want.cpp : >> int myclass::fx(int * arg) >> { >> if(! (isValid())) >> { >> return -1; >> } >> >> return ptr->fx(arg); >> } >> >> The commands I have tried are : >> >> i) >> sed -e 's/\(}$\)\n\(^[[:space:]]*[[:alpha:]]\+\)/\1\n\n\2/' \ >> what-i-want.cpp >> >> ii) >> sed -e 's/\(}$\)\(^[[:space:]]*[[:alpha:]]\+\)/\1\n\2/' \ >> what-i-want.cpp >> >> but obviously neither works, which is why posting this message. >> >> Can anybody please tell me what the correct command would be like ? >> > > Seems like this would work to add a space only to lines where the next > line only has a new line : > > sed ' /\}$/ { N /}$\n\n/ { s/\}$\n/\} $\n/} } ' file > > If the possibility exists that the new line might have spaces as well, > you could do this: > > sed ' /\}$/ { N /}$\n\n/ { s/\}$\n[ ]?/\} $\n/} } ' > > Note: I haven't tested this, so it may require some modification. Read > this page on dealing with multiple lines in sed to gain further > understanding - http://www.grymoire.com/Unix/Sed.html > Hello Paul, After reading the sed document, the following worked for me : sed ' /}$/ { N s/}\n\([[:space:]]\+\)\n*/}\n\n\1/ }' what-i-want.cpp This keeps the indentation intact. Thanks for the help & -- Regards Manish Jain invalid.pointer@gmail.com +91-96500-10329 Laast year I kudn't spell Software Engineer. Now I are won.