Skip to content
Advertisement

bash: string value based entries filtering

I have this check in my script:

JavaScript

It is writing lines that contain contact* from one file to an array. How can I add another check that will skip the xi* values in that line and write it in the array?

I tried something like:

JavaScript

But it is not working for me. :/

Advertisement

Answer

The first file looks like this:

JavaScript

The second file needs to look like this:

JavaScript

So, without the xi* in the contact* lines.

Since the xi* is at the end of the $VALUE, you can simply use the bash Parameter Expansion Remove matching suffix pattern:

JavaScript

xi* values aren´t always at the end of the line

If the xi* is amid the $VALUE elements, you could use Pattern substitution:

JavaScript

and if there are multiple xi* values?

To delete multiple xi* elements, you just have to double the / above:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement