-1
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.icc.id</groupId>
        <artifactId>idp-parent</artifactId>
        <version>7.0.1.0-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <artifactId>app</artifactId>
    <packaging>war</packaging>
    <name>${project.name} - Hello World Web App</name>

    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>solution-commons</artifactId>
            <version>${com.icc.id.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>application-common</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-hazelcast</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-health</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-rabbitmq</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-rest</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-security</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-system</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>framework-commons-web</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>platform-connector-cache</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>platform-connector-spring-remoting</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>platform-openid-connect</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>com.icc.id</groupId>
            <artifactId>platform-rest-commons</artifactId>
            <version>${com.icc.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- The following log4j 1.2 bridge is needed to satisfy libraries that has runtime dependency on log4j 1.2. -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-1.2-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
        </dependency>
        <dependency>

</project>

So pom.xml could be something like this..So the requirement is that scan each line and search for com.icc.id , if it is found then replacement should only happen if n+2 line does not contain com.icc.id.version (version line contains com.icc.id.version). If it does not contains - com.icc.id.version, groupid should be replaced to com.uxpsystems.$1 (where $1 is passed as argument to this script) If it contains, skip that block and check the next line if it contains com.icc.id

  • 1
    It's XML so this shouldn't be about scanning lines but rather about matching elements and paths. Use the right tool for the right job. – roaima Jun 21 at 16:34
  • I suggest to use an XML/HTML parser (xmlstarlet, e.g.). – Cyrus Jun 21 at 16:51
0

either parser or load lines into buffer like this:

awk '{line=line1;
      line1=line2;
      line2=$0;}
     /com.icc.id.version/ { if (line ~ "com.icc.id")
       { line = ... replace ... }
     }
     {print line}
     END {print line1; print line}'

Note: I've not tested, but it should be very close

0

Since we are injecting data(by means of $1) into the rhs of a s/// sed command, we need to quote it properly, so that when it gets plugged into the sed code, no errors should be triggered.

Note: As has been pointed out to you already, the right way to approach this is via an xml tool.

$ v1_esc=$(printf '%s\n' "$1" | sed -e 's:[\/&]:\\&:g;$!s/$/\\/')
$ sed -e '
   /com[.]icc[.]id/!b
   $!N;$!N;/\n.*\n/!q
   /.*\n.*\n.*com[.]icc[.]id[.]version/b
   '"s/com[.]icc[.]id\\(.*\\n.*\\n\\)/com.uxpsystems.${var}\\1/"'
' pom.xml

Explanation:

  • Skip noninteresting lines and print them out as is.
  • Grab 3 lines, starting the count from the interesting line.
  • While in this process of grabbing 3 lines, you run out of lines, meaning, you reach the eof, then just bail out and print the pattern space as is.
  • if we have managed to reach here, means we have 3 lines in the pattern space for sed to look at and the first of those is the interesting line.
  • skip processing this block of 3 lines in case the 3rd does not happen to have the prescribed string com.icc.id.version in it, and print it as it is.
  • we are here means, the right block of 3 lines has at last been detected and now you should be performing the desired subsitution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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