Script Linux Bash, print grep output based on number of words in line

I’m trying to write a scirpt for the bash shell. I’m given 4 parameters:

  1. path of a directory
  2. extension of a file
  3. a word
  4. a number

I have to look for all files and files of subdirectories of the path, for files with the given extension. Then, look in the files for the lines matching the word given, but only if the number of words in the line is bigger or equal to the number provided.
For example:
If localDirectory has: image.png script.sh text.txt.
And text.txt has:

This is a text file
It contains many words
This is an example for a simple text file

Then give the command: ./example.sh localDirectory txt text 7
I should output: This is an example for a simple text file.

For now, my script looks like this:

if [ "$#" -ne 4 ];
then
  echo "Not enough parameters"
  exit 1
fi
find $1 -name "*.$2" -exec grep -wi $3  {} ;

And it works just fine for the first 3 goals, I just don’t know how to filter now the result such that the line has a greater or equal number of words as $4.

I could of course create a new file and output there, and then read from it and print only the relevant lines, but I would rather do this without creating new files.

I’m very new to shell scripting.

Any ideas?

Webform Computed Data Display Grade and Text based on result

I am building a quiz using webforms and the computed data twig and have a question if something is possible and if there is documentation on how to build this.

The quiz is 20 questions and each answer has a value of 1-5, I have all of the computed data working and it is able to show the final score properly, but was wonder if I could assign a grade and give short text feedback based on the score.

For example:
A user scores less than 70 they would receive a grade of “Below Average”, 70-80 Average and 81-100 “Above Average” and then some text giving them feedback on their score depending on this range they scored in. Is this possible to do in webforms?

Thank you so much for any help!

magento2.3 – Create a ResourceModel based on 3rd Party API Call from Magento

I am working on integrating a 3rd Party API into Magento. I’d like to use an Admin Grid with a Data Source that comes from a 3rd party API. So Essentially the Flow work like this…
User Loads into admin page with grid -> grid has data source specified to resource model -> resource model calls 3rd party api to get data -> data is returned to resource model(not sure if its supposed to be resource model or collection or factory in this scenario) -> data is bind through the resource model to the grid.

If there’s any additional information needed please let me know. I’m not sure what all information might be helpful.

windows – batch script create columns based on amount of files

I have a .txt-File which should be extended based on how many files there are in a folder.
The .txt-File looks like this:

---------------------------------------------------------------------------
File 1
---------------------------------------------------------------------------

File-Name...............:
File-Size...............:

---------------------------------------------------------------------------
File 2
---------------------------------------------------------------------------

File-Name...............:
File-Size...............: 

---------------------------------------------------------------------------
File x
---------------------------------------------------------------------------

File-Name...............:
File-Size...............: 

---------------------------------------------------------------------------

For further explanation of my question, let’s define one set of strings as one collumn:

---------------------------------------------------------------------------
File X
---------------------------------------------------------------------------

File-Name...............:
File-Size...............:

---------------------------------------------------------------------------

Now I want to a batch-Script to check for the amount of files inside the directory and
create copies of the collumn based on the amount of inside the directory to a local .txt-file.
It should also replace X with an ascending number.

This is my code so far:

@echo off

for /f %%A in ('dir /a-d-s-h /b ^| find /v /c ""') do set cnt=%%A
echo %CNT%

... //This is the lone where I want to copy the collumns based on the amount files

echo * >>test.txt //this is where I want to save it as a string

sharepoint online – SPO: Using JSON to Show/Hide Modern Form Field Based on Value Selected in Lookup Column

I am trying to modify the new-entry form of a modern list in SharePoint Online by hiding or showing a field based on the value selected in a preceding field on the same form. Microsoft offers straightforward guidance on how to do this using a JSON snippet.

While they don’t list a lookup column as an unsupported field type to use for this purpose, they don’t provide guidance on how to use one in this way, either. And from my testing, you can’t simply grab the value of a lookup field in the described way:

=if(($LookupField)=='Hourly', 'true', 'false')

If I use a choice field instead of a lookup field, this works fine. But doing some digging, in other contexts it looks like the value may be captured in a .lookupValue property, so I tried it this way:

=if(($LookupField.lookupValue)=='Hourly', 'true', 'false')

Still no luck. Does anyone know if it is possible to use the value from a lookup field in this way? And if so, what do I need to do to make the magic happen?

Does designing an automatic interaction based on user intent a good thing?

We have this flow in our interface where user can unlink their accounts that are connected to the application. We have a button to unlink their bank, but we also have an option where user can manually unlink each account. The process here is quite tricky because they need to click the “submit” button once they are okay with their changes, reason being they need to enter 2FA,and we do not want them to enter 2FA for each change or unlink that they do for each account if needed. Sorry for the bad sketch but this is how it is currently laid out:
enter image description here

In cases that user tries to manually unlink each account and does not use the “unlink bank” option, the suggested interaction is when user clicks the last account with the “Unlink”, the system will detect their intent to unlink all accounts and the bank and will show a confirmation dialog if they want to unlink the bank:
enter image description here

It is a good interaction as it detects the intent of the user and it removes one step which is clicking the “update” button, however my concern is that clicking on the last “unlink” button and then showing a confirmation dialog after might be something unexpected? I’m not sure if the modal interrupts the user work flow since it is detecting that it wants to unlink all accounts which equals to unlinking the bank and one less click of clicking the update button, while the modal offers a second chance whether to cancel or not. Is there an article that would suggest this is a bad idea?

We cannot do user testing at the moment that is why this is challenging. But I’d like to get your thoughts or if you have any articles you could share that relates to this topic, that would be really helpful.

How to join public group in Telegram group based on an invite code

Someone provide this: tg://join?invite=xxxxxxxx
(UIApplication sharedApplication) openURL:(NSURL URLWithString:@"tg://join?invite=xxxxxxxx") options:@{} completionHandler:^(BOOL success) {});

  1. if the xxxxxxx is private invite code, it worked.
  2. if the xxxxxxx is public invite code, the telegram show "This invite link has expired"
    What do I do?

How to aggregate values from fields in Paragraphs based on value of another field in that same paragraph, and display in an aggregated Views table?

Hopefully my title makes sense…

I am setting up a Drupal 9 website for internal use as a financial reporting engine and a CRM. I am making use of the following modules:

  • Paragraphs
  • Views
  • Viewfield
  • View Fields View
  • Views Aggregator Plus

I have one Paragraph (Entity Reference) unlimited-value field on a paragraph type called “Project”. That field is called “Transactions”. It refers to a paragraph type called “Transaction”.

The “Transaction” paragraph type has the following fields:

  • Transaction Amount (decimal field))
  • Status (term reference field. Values are PAID and UNPAID)
  • Paid On (date field)
  • Year (a taxonomy entity reference field that contains pre-set years (2019, 2020, 2021, etc).

I have a content type called “Company”. It has the following fields:

  • Title
  • Project (a Paragraph/Entity Reference field)
  • Transaction Amount – Paid (a Viewfield)
  • Transaction Amount – Unpaid (a Viewfield)
    • These two Viewfields are of content type “Company”
      • One is filtered to the Transaction paragraph’s status “Paid”; the other is filtered to “Unpaid”.
    • They contain this field, which is SUMmed through Views Aggregation: (field_transactions: Paragraph) SUM(Paragraph: Transaction Amount)
    • They contain these relationships:
    field_projects_paragraph: Paragraph
    (field_projects_paragraph: Paragraph) field_transactions: Paragraph
    (field_projects_paragraph: Paragraph) field_transactions




    

The output displays the sum of the paid or unpaid transactions. For example, if a company has a project which has 3 PAID transactions of $100 each, this view will output “$300”. The intent is to display this value on the “Overview of Transactions” view, as described below:

Overview of Transactions view…

I have created a View of “Company” content of display format: “Table with Aggregation Options” that will display a table of the following columns:

  • Company Title
  • Total Transaction Amount (a SUM aggregation of all transaction “Transaction Amount” values.
  • Total Transaction Amount with status = PAID
  • Total Transaction Amount with status = UNPAID

The intent is to display an at-a-glance table of all Companies on the site, showing a line for each Company, that Company’s Total Transaction amount (which includes paid and unpaid), that company’s PAID total amount, and that company’s UNPAID total amount.

Further, the intent is to be able to filter this table based on the “Year” taxonomy term value from the Transaction paragraph type (filter it to only contain data that is tagged with “2020”, for example), or to filter it by date range using the “Paid On” value from the Transaction paragraph type (filter it to only contain data that contains a date value of 01/01/2020 – 01/03/2020, for example). The purpose is to be able to see all dollar amounts per company on a yearly, monthly, weekly, daily, or any other date range basis. For example: “display all company transaction data for Jan 1, 2020 through March 31, 20020, and then run that same report for that same time period in 2021.

To the View, I added the following settings:

Relationships:

    - field_projects_paragraph: Paragraph
    - (field_projects_paragraph: Paragraph) field_transactions: Paragraph

Filter Criteria:

    Content: Content type (= Company)
    (field_transactions: Paragraph) Paragraph: Year (exposed)
    (field_transactions: Paragraph) Paragraph: Paid On (exposed)

Fields:

    Content: ID (ID) (hidden)
    (field_transactions: Paragraph) Paragraph: ID (ID) (hidden)
    Content: Title (Title)
    (field_transactions: Paragraph) SUM(Paragraph: Transaction Amount) (Transaction Amount)
    Content: Transaction Amount - Paid (Transaction Amount - Paid) - This is one of the Views Field View fields from the Company content type
    Content: Transaction Amount - Unpaid (Transaction Amount - Unpaid) - This is one of the Views Field View fields from the Company content type

Format:Table with aggregation options

        ID: Apply Group Function: Group and Compress
        (field_transactions: Paragraph) Transaction Amount: Column Aggregation: Sum

    

My current end result is as follows:

  • Each Company has its only single line in the table.
  • The “Total
    Transaction Amount” field correctly sums the company’s total
    transactions (paid and unpaid), and the column successfully
    aggregated the total transactions of all Companies on the site.
  • The
    “Content: Transaction Amount – Paid (Transaction Amount – Paid)”
    field correctly displays the company’s total PAID transactions, but
    it does not adhere to the Year and Paid On filters. Additionally, the
    column will not SUM with the Table Aggregation settings at all.
  • The
    “Content: Transaction Amount – Unpaid (Transaction Amount – Paid)”
    field correctly displays the company’s total UNPAID transactions, but
    it does not adhere to the Year and Paid On filters. Additionally, the
    column will not SUM with the Table Aggregation settings at all.

How can I display each company’s Paid and Unpaid transaction totals in this Views aggregated table, and also make those two values subject to the Year and Paid On filters?

I am open to completely re-thinking the organization of the node types, data, etc.

PostgreSQL cascading triggers based on the condition of which other table triggered it or a value given by the other trigger?

I want to keep (slightly different) tables synced to one another and with only 2 tables, this is fine. Because of pg_trigger_depth() = 0 in the WHEN clause they will not trigger each other.

I currently have the following database triggers defined:

Table From Trigger Table To
V1 V1 -> V2 V2
V2 V2 -> V1 V1

But I now want to have a V3 (or even more, V4, V5) table that also has to be synced. I want the triggers to trigger after one another but only in the right direction, e.g. V1 -> V2 -> V3, V3 -> V2 -> V1 or when V2 gets an insert/update/delete from V2 to V3 and from V2 to V1.

So my question is is it possible to come up with a solution that if V1 gets an insert/update/delete it first updates V2 and then only triggers the trigger from V2 -> V3 and not also the one from V2 back to V1.

I was thinking of some kind of ‘forwards’ and ‘backwards’ value when pg_trigger_depth() is not 0. Because a trigger is always either forward or backwards it can maybe be built into the trigger that it only triggers other ‘forwards’ or ‘backwards’ triggers when pg_trigger_depth() > 0.

Table From Trigger Table To
V1 V1 -> V2 V2
V2 V2 -> V1 V1
V2 V2 -> V3 V3
V3 V3 -> V2 V2
V4 V4 -> V5 V5
V5 V5 -> V4 V4

A different solution I can think of is to make a trigger from every table to every other table but this can quickly become too much when a new, for example V5, table gets added. In the above question only 2 triggers will have to be defined, but in this case 8 new triggers with slightly different changes will have to be made.

normalization – How do I identify functional dependencies and normalize a table based on the attributes?

I’m having trouble identifying the combination of attributes which make up Functional Dependencies(FDs) of a particular table. While I understand how Normalization process works when given the FDs, I’m unable to translate and identify FDs for a given table.

I’ve been tasked to create a database of a company which tracks all expenses of sales/packages etc. Naturally that means storing Customer information for the company to identify all consumers.

CREATE TABLE Customers (
    id        integer primary key,
    address   text not null,
    name      text not null,
    email     text unique not null,
    phone     text unique not null,
    unique(name, address)
);
    

I’ve chosen to represent the info for the customer table as such, given that each phone number and email is uniquely tied to the customer. The unique constraint allows for multiple people from the same household address to be present in the table.

I want to see if I can normalize this table further, however I am unable to identify the attributes to determine the FDs needed.