Question: Basically (said slightly tongue-in-cheek) I have a csv file in a format like this:

```
"ID","Name","Phone Number"
"00001","Ricky Stallman","07771111111"
"00003","Harrison Ford","07701010101"
"00003","Harrison Ford",""
"00008","Bob Geldof","07712121212"

```

Where the 'Harrison Ford' entry appears again in my csv there's no number next to it (it's just the way the data is annoyingly presented to me). I need the csv to read like this (i.e with the number from the row above to be copied into the field below):

```
"ID","Name","Phone Number"
"00001","Ricky Stallman","07771111111"
"00003","Harrison Ford","07701010101"
"00003","Harrison Ford","07701010101"
"00008","Bob Geldof","07712121212"

```

Preferably in Bash if anyone has a suggestion?

Answer: 
Try this:

```
awk -F',' '$3!~/""/{nbr=$3} {print $1","$2","nbr}' file

```

If the third column is "" then use the last valid value.
A gawk solution could be used:

```
#!/usr/bin/gawk -f

match($0, /"([^\"]*)".*,"([^"]*)","([^"]*)"/, t) {
    key = t[1] "|" t[2]  ## Or just key = t[2] to be less strict.
    if (!(t[3] == "" && key in a)) {
        a[key] = t[3]
    }
    printf "\"%s\",\"%s\",\"\"%s\"\n", t[1], t[2], a[key]
}

```

Condensed:

```
gawk 'match($0, /"([^\"]*)".*,"([^"]*)","([^"]*)"/, t) { key = t[1] "|" t[2]; if (!(t[3] == "" && key in a)) a[key] = t[3]; printf "\"%s\",\"%s\",\"%s\"\n", t[1], t[2], a[key] }' file

```

Output:

```
"ID","Name","Phone Number"
"00001","Ricky Stallman","07771111111"
"00003","Harrison Ford","07701010101"
"00003","Harrison Ford","07701010101"
"00008","Bob Geldof","07712121212"

```