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
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?
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.. 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