Hi,
I am having an '.xml' file with 'n' number of lines and also having another file with '.txt' format contains values which i want to search.
Now I want to print the next line with the pattern which i am searching in '.xml' file. And the loop has to repeat for different patterns which are present in '.txt' file.
the logic which i used is
while read line
do
grep -h -e $line -A 1 file1.xml >> values.txt
done < file2.txt
the above code is working in Linux server. Where I tried the same code in AIX server, it thrown below error
.rep: 0652-033 Cannot open
grep: 0652-033 Cannot open -A.
grep: 0652-033 Cannot open 1.
.rep: 0652-033 Cannot open
grep: 0652-033 Cannot open -A.
grep: 0652-033 Cannot open 1.
..................
Please help me out from this.
The -A
flag is a gnu extension to the grep
command, try something like the following (untested) code.
perl -e 'while(<>){open XML , "<", "file1.xml") ;chomp; $pattern=qr(\Q$_\E/);while(<XML>){print scalar readline(XML) if (/$pattern/);}}' file2.txt
AIX has a different version of grep
. It has no -A
and -B
switches.
Here are threads with solutions:
Hi,
I tried with the above perl command, but its thowring error.
where my xml file contains,
<NameValuePair>
<name>Security/SharedResources/Shared/JNDI/Username</name>
<value>user</value>
</NameValuePair>
<NameValuePair>
<name>Security/SharedResources/Shared/JNDI/Password</name>
<value>u23r</value>
</NameValuePair>
<NameValuePair>
<name>Security/SharedResources/Shared/JNDI/URL</name>
<value>tibjmsnaming://aix123.ttgplc.net:11240,tibjmsnaming://aix123.ttgplc.net:11240</value>
</NameValuePair>
<!--- Public EMS Server Settings -->
<NameValuePair>
<name>Security/SharedResources/Shared/JNDI-Public/Password</name>
<value>u23r</value>
</NameValuePair>
<NameValuePair>
<name>Security/SharedResources/Shared/JNDI-Public/Username</name>
<value>user</value>
</NameValuePair>
<NameValuePair>
<name>Security/SharedResources/Shared/JNDI-Public/URL</name>
<value>tibjmsnaming://aix123.ttgplc.net:11230,tibjmsnaming://aix123.ttgplc.net:11230</value>
</NameValuePair>
and the patterns which i want to search are placed in a txt file, contains,
Security/SharedResources/Shared/JNDI/Password
Security/SharedResources/Shared/JNDI/ContextUrl
Security/SharedResources/Shared/JNDI/Username
Security/SharedResources/Shared/JNDI-Public/Password
Security/SharedResources/Shared/JNDI-Public/ContextUrl
Security/SharedResources/Shared/JNDI-Public/Username
Now i want to print the next line of xml file using the above patterns and save it to another file.
Please help me out from this issue..
---------- Post updated at 12:37 AM ---------- Previous update was at 12:36 AM ----------
the logic has to be work in AIX server..
while read line; do nawk -v l="$line" '$0~l{getline;print;exit}' file.txt; done < pattern.txt