Hi
I want to create a shell script with the following awk command & also get the filenames in output.
awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' *.xml
As there will be multiple outputs related to many xml files I cannot identify which output belongs to which file
can anyone help?
Hello sharp488,
Welcome to forums, could you please try following and let me know if this helps.
for file in *.xml
do
echo "File name which is processing currently: " $file
awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' $file
echo "******************************"
echo ""
done
Thanks,
R. Singh
Its giving me error
$ ./roottelnet.sh
./roottelnet.sh: line 2: syntax error near unexpected token `$'do\r''
'/roottelnet.sh: line 2: `do
Hello sharp488,
Seems you may have carriage characters in your script which you are using, could you please use following command to confirm the same.
cat -v Input_file
Where Input_file is your script name. If you are seeing control M characters there like as an example as follows.
again test test1 test1 test2^M
test test test1 test chumma.^M
If you find above control M characters into your script then you could try following to remove them.
awk '{gsub(/\r/,X,$0);print}' roottelnet.sh > tmp_roottelnet.sh
mv tmp_roottelnet.sh roottelnet.sh
Then you could try to run your script. Kindly do let us know if you have any queries on same.
Thanks,
R. Singh
RudiC
October 25, 2016, 9:35am
5
Try (untested):
awk '/<catetcsecuretty0>/ {p=1; print FILENAME ":"} /<catvarlogmessages0>/ {p=0} p' *.xml
i did a vi
on the file its showing
for file in *.xml
do
echo "File name which is processing currently: " $file
awk '/<catetcsecuretty0>/ {p=1} /<catvarlogmessages0>/ {p=0} p' $file
echo "******************************"
echo ""
done
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
---------- Post updated at 07:47 PM ---------- Previous update was at 07:41 PM ----------
Thank You.
Its working