Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: add a line of text above a matching pattern

geek:

I have bunch of .cpp files. say tes1.cpp


example
//commented
abc
def

test2.cpp


efg

test3.cpp


def
efg

I need to write a script,


find which file has abc pattern,
if found need to find if it has //commented pattern,
if it is found then find if //additional text,
if not found then add a line of text //additional comment above //commented

output file should be, test1.cpp


example
//additional comment
//commented
abc
def

i tried with


if grep -Erl '\babc\b' *; then
if grep "//commented" ; then
echo "Already updated"
else
sed '\/\/ commented /i\// additional comment'
fi
fi

but execution hangs. how do i do it?



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: add a line of text above a matching pattern

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×