Copy from/to file, if arg 'ok'

Hello, I've just started with shell scripting, and I need som assistance!
Basicly what I want to do is copy names from one file to another, when running the scrip the user should be asked about the status of these names.
Let me demonstrate:

file:

Name: John, Gender: male 
Name: Jane, Gender: female

// when the script is running

Is Johns status ok y/n? n
Is Janes status ok y/n? y

newfile:

Name: John, Gender: male, Status: -
Name: Jane, Gender: female, Status: ok

I know how to copy a file, but I really don't even know where to start here! Help is appreciated!

Is this a homework assignment?
What shell are you using?
Have you read the description of the read and printf built-in utilities on your shell's man page?

I am using the bash shell in ubuntu, it's an exercise, I have not read the printf I will do it now, thx

What have you done so far?

Well, I have learned how to copy from one file to another, but I'd like to know how to add a field in the new file, depending on what the user enters. I understand I might jump into things alittle fast.. :confused: so if you have tips on tutorials that be great

In a while loop we read the input file line by line, and write each line to the output file.
We associate descriptors 3 & 4 rather than the default 0 & 1, so another read/print (for interactive i/o) won't interfere

#!/bin/sh
while read line <&3
do
  name=`expr "$line" : "Name: *\([^,]*\)"`
  printf "Is %ss status okay y/n? " $name
  read status
  if [ "$status" = "y" ]
  then
    status="ok"
  else
    status="-"
  fi
  printf "$line, Status: $status\n" >&4
done 3< file 4> newfile
2 Likes

This was a huge help, ty! I can now finally continue with this script! (.. don't know if I should be happy or upset for making it look so easy :smiley: )