Caveat: Absolute beginner. I need to add a column to a .csv file where the column header can be "Name", but the entire column should be exactly the same -- the name of the file itself, the filename
. Each file has only 3 variables now, but 2100 rows.
Example: For file "bcc1_45Fall_10010002.csv" this is what I have -
HUC8 YEAR RO_MM
10010002 1961 74.7
10010002 1962 69.1
10010002 1963 52.0
10010002 1964 130.7
10010002 1965 32.2
10010002 1966 85.4
This is what I want -
NAME HUC8 YEAR RO_MM
bcc1_45Fall_10010002 10010002 1961 74.7
bcc1_45Fall_10010002 10010002 1962 69.1
bcc1_45Fall_10010002 10010002 1963 52.0
bcc1_45Fall_10010002 10010002 1964 130.7
bcc1_45Fall_10010002 10010002 1965 32.2
bcc1_45Fall_10010002 10010002 1966 85.4
OR this -
HUC8 YEAR RO_MM
bcc1_45Fall_10010002 1961 74.7
bcc1_45Fall_10010002 1962 69.1
bcc1_45Fall_10010002 1963 52.0
bcc1_45Fall_10010002 1964 130.7
bcc1_45Fall_10010002 1965 32.2
bcc1_45Fall_10010002 1966 85.4
If I could simply replace all the data in the "HUC8" column with the filename
that would be perfect. It doesn't need to be an extra column.
I need to do this for many thousand files.
If I knew how to do the first part, I could then create a loop. But maybe there's even a better way?
I don't know where to begin.