Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grep Question 2

Status
Not open for further replies.

SirB

IS-IT--Management
Oct 23, 2008
8
0
0
US
Hi everybody,

I am trying to isolate the String before the ".xml". Do you know how to do that with a grep command. The file contains one example of more than two thousand different strings all having the .xml attached.

Many thanks in advance.

[ERROR]: 2008-10-10-14:30:01:851 in Transformation_27 com.hp.
Transformation: Unable to create the document: /tools/trafo_p
esrsp/SEND/tspnormal.ch/TSP/B3450_E83ABGL/B3450_E83ABGL.xml
 
Not quite sure what you mean or if you only want to use grep

Something simple with awk could echo the imput before .xml

Code:
cat <file>|awk -F ".xml" '{print $1}'

On some systems awk does not work with -F - but then nawk could be an option.
 
I'm guessing that the input data really looks like this:

Code:
[ERROR]: 2008-10-10-14:30:01:851 in Transformation_27 com.hp.
Transformation: Unable to create the document: /tools/trafo_pesrsp/SEND/tspnormal.ch/TSP/B3450_E83ABGL/B3450_E83ABGL.xml

In which case try:

Code:
awk '/.xml/ { sub(".xml","",$NF); print $NF }' inputfile > outputfile

Annihilannic.
 
Hi

Some [tt]grep[/tt] implementations have -o option :
man grep said:
-o, --only-matching
Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
The ugly part is that the ".xml" will be also be included in the output :
Code:
grep -o '[^ ]*.xml' /input/file

Feherke.
 
Hi,

many thanks for the quick responses. This helped a lot!

Question: Is it possible to grep the string between the / and the .xml, which would be in this case B3450_E83ABGL.
If it was "B3450_E83ABGL.xml", would be also fine.

Thanks again in advance for your help.

rgds
 
Hi,

nice one. Many thanks feherke.

That worked.

rgds
 
Hi everybody,

this time I need the document name, eg. in this case it is B6300_46005.

Many thanks for your help in advance.

[ERROR]: 2008-12-16-19:31:14:838 in Transformation_15 com.hp.antares.trafo.core.Transformation: Transformation of this document failed: B6300_46005
com.hp.antares.trafo.core.TransformationException: Could not identify TypeCode of document!
at com.hp.antares.trafo.core.Transformation.run(Transformation.java:708)
 
Hi Feherke,

I tried this and it worked:

awk '/ failed:/ { sub("failed:","",$NF); print $NF }' inputfile > outputfile

But I dont know what the code does...:-o)

many thanks anyway
 
Hi

Code:
/ failed:/ {              [gray]# current record contains the string ' failed:', do :[/gray]
  sub("failed:","",$NF)   [gray]# replace the string 'failed:' with nothing in the last field[/gray]
  print $NF               [gray]# print the last field of current record[/gray]
}

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top