How to pass a function with a variable parameter into another variable?

Hello again :slight_smile:

Am currently trying to write a function which will delete a record from a file.

The code currently looks as such:

 
function deleteRecord() {
clear
                read -p "Please enter the ID of the record you wish to remove: " strID
                output=$(grep "$strID" recordDatabase)
                recordExists=findRecord $strID
 
#code will go here to check that recordExists returns a value.....

I hope what I am trying to do makes sense, the function findRecord searches the file for examples which match the ID. This works fine.

I simply need to store the returned value of findRecord $strID in recordExists.

Thanks in advance :slight_smile:

Mikey

Well, usually the grep needs to be anchored into one field.

Deleting a record from a file is usually making a new file without the record (grep -v).

Sed could find the delete records and divert them to a side file using the w and d options.

sed '
  /^'"$strID"':/{
    w side_file
    d
   }
 ' < original_file > new_file

Show us what input you have and what result you need?