Hello,
OK, thanks - if you can get back to us with that information, that would be great.
By way of general advice however, the awk
utility is quite often one of the tools that people choose when wanting to pick out a particular piece of data from a file. In the most commonly-encountered usage case, awk
is used to print a particular numbered field out of its given input, optionally with a specific field delimiter being specified.
So, let's imagine we have a fairly simple sample file that looks like this:
$ cat fruits.xml
<Fruits>
<Value1>Apple</Value1>
<Value2>Orange</Value2>
<Value3>Banana></Value3>
</Fruits>
$
Now let's say we've been tasked with printing the contents of the Value2
field from this file. We can use awk
, like so:
$ awk -F '[<>]' '/Value2/ {print $3}' fruits.xml
Orange
$
Let's break down bit-by-bit what we've seen here. Firstly, this part of the awk
command specifies the field separator:
-F '[<>]'
The -F flag tells awk
that we're setting our field separator, and in this case we're using a multi-character field separator. The effect of putting multiple characters within the square brackets is to consider any of the characters within as a field separator. So in our case, any angled bracket will be regarded as the start or end of a field, as appropriate.
Next, we have this part of our command:
/Value2/
This tells awk
that we want it to search through its input for lines which match the pattern "Value2". We choose this because, in our example, this is the particular field we want to print the contents of.
Lastly, we have this:
{print $3}
This, quite simply, tells awk
to print the third field. Now, remember that our field separator is either an opening or closing angled bracket. So in the case of our sample line, awk
would therefore now read it thusly:
<Value2>Orange</Value2>
^ ^ ^
| | |
| | 3rd field
| |
1st field 2nd field
So the empty space (before the first angled bracket) is field 1; the string "Value2" (after the first angled bracket) is the field 2; and the string "Orange" (after the second angled bracket) is field 3.
So the end result is that we get the output we want, namely the contents of "Value2" within our sample file.
Anyway, hope this helps !