# Applying Pattern to Line

*Apply Pattern to Line* is useful when the specified pattern does not capture the first line of the desired data region or when there is some information above the pattern keyword. In that case, we increase *Apply Pattern to Line* from 0.

{% embed url="<https://youtu.be/4W81lItRN2U>" %}

## Loading Unstructured File

1\. Open a *Report Model* in Astera by going to *File > New > Report Model.*

<figure><img src="https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/MFwVCPQpk8IC4duwi096/image.png" alt=""><figcaption></figcaption></figure>

2\. Select your file in the window that opens.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/ft7Kt2FQ8JjUd3ykT9Fw/02%20Specify%20file.png)

Download the sample txt file from [here](https://www.astera.com/Downloads/Misc/2020/07/16-Apply-pattern-to-line.zip).

{% file src="<https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/Ja1HzV9lUwpKKYH5SXl9/Apply-pattern-to-line.zip>" %}

Astera supports extraction of unstructured data from text, EDI, Excel, PRN, and PDF files. In this example, we are extracting data from a text file. Download the sample text file from here.

There are many options available on the *Report Options* panel to configure how you want Astera to read your file. The reading options depend on the file type. For example, if you have a PDF file, you can select the scaling factor, font, tab size, and passwords.

You can read about these options [here](https://documentation.astera.com/report-model/report-model-interface/report-options).

3\. Click *Open*. A text file containing contact information will open in Report Model designer.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/bnYHfGYU9mvM41PFq40T/ApplyPatternToLine_1.PNG)

Now that our file has been loaded to Astera, we will create an extraction template.

## Creating a Report Model

1\. Right-click on the *Record* node in Model layout under the Report Browser panel. Select *Add Data Region.*

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/bjDySnHY1ffrLiUtP3bL/ApplyPatternToLine_2.png)

A pattern box, Region Properties panel, and *Pattern Properties* panel appears above the Report Model designer.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/TO6ggbIdEeq3G4aLgQe6/ApplyPatternToLine_3.PNG)

2\. Specify a pattern that Astera can match on your file to capture data. In this example, we want to capture the data region highlighted in yellow.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/6ZqbaoY7Uv8jlIecxcIn/ApplyPatternToLine_4.PNG)

For this, write "Contact Information" in the pattern box to match it on the file as shown below.

<figure><img src="https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/gUHiCc2QrawrDCXohJZr/image.png" alt=""><figcaption></figcaption></figure>

3\. Notice that specifying a pattern alone is not enough to capture the entire data region in this example. Hence, we will increase its *Line Count* to 9.

<figure><img src="https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/AKoeoGGpqsdxSf6ZNB51/image.png" alt=""><figcaption></figcaption></figure>

Observe that the data in lines above the data region (highlighted in grey) is still not captured.

<figure><img src="https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/FFauZNhOXR4GlLJ0qU6i/image.png" alt=""><figcaption></figcaption></figure>

4\. To capture data in these lines, increase the *Apply Pattern to Line* to 1 in the Pattern Properties panel as shown below.

<figure><img src="https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/FyeqOwGJ2DZHLHU4jAG8/image.png" alt=""><figcaption></figcaption></figure>

Now, the region is completely captured.

<figure><img src="https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/IaUvZ3uyCpUx2pTbPJEQ/image.png" alt=""><figcaption></figcaption></figure>

5\. Once our data region has been defined, the next step is to create fields. For that, highlight each field area, right-click and select *Add Data Field.*

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/43aeX7Sx0tPxvC4gqJAh/ApplyPatternToLine_10.png)

Repeat the process to create more data fields and name them as shown below. You can see the layout of the extraction template in the Model Layout panel.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/MNkCeDOapjALozJj00Xh/ApplyPatternToLine_11.PNG)

6\. Preview data by clicking on the *Preview Data* icon placed in the toolbar at the top of the designer window. It will first ask you to save the file.

Once saved, a Data Preview window will open displaying a preview of the extracted data.

![](https://content.gitbook.com/content/zEifS4h8yurLAAwiGNX2/blobs/MPc6PLUBU12mbxu2WuTM/ApplyPatternToLine_12.PNG)
