Hi,
I have an awk script that I've been using to parse some data from a file. The source data has some things that are inaccurate, so I'd like to replace certain strings with data from another file.
Here's what I originally was using for one section:
/^department:/{departmentnumber = index($2, "-") ? substr($2, 1, index($2, "-")-1) : $2 ; department = substr($2, 5); fulldepartmentname = $2}
This would parse out the ###-Some information. What I'd like to do now is get the department data from a separate file.
My first pass at it was:
/^department:/{departmentnumber = index($2, "-") ? substr($2, 1, index($2, "-")-1) : $2 ; department = system("grep ,departmentnumber$ /tmp/employee_departments.txt | awk -F"," '{print $1}'"); fulldepartmentname = "departmentnumber"-"department"}
But I don't think I've formatted it entirely correctly.
Sample input:
department: 999000-Should really be marketing
Sample output:
"999000","Marketing","999000-Marketing"
The employee_departments.txt has the data in this format:
Department_Name,Number
So it would look like this:
Marketing,999000
I'm executing the script with awk -f script.awk datafile
Any suggestions as to how to best proceed would be greatly appreciated.
Thanks!
I have an awk script that I've been using to parse some data from a file. The source data has some things that are inaccurate, so I'd like to replace certain strings with data from another file.
Here's what I originally was using for one section:
/^department:/{departmentnumber = index($2, "-") ? substr($2, 1, index($2, "-")-1) : $2 ; department = substr($2, 5); fulldepartmentname = $2}
This would parse out the ###-Some information. What I'd like to do now is get the department data from a separate file.
My first pass at it was:
/^department:/{departmentnumber = index($2, "-") ? substr($2, 1, index($2, "-")-1) : $2 ; department = system("grep ,departmentnumber$ /tmp/employee_departments.txt | awk -F"," '{print $1}'"); fulldepartmentname = "departmentnumber"-"department"}
But I don't think I've formatted it entirely correctly.
Sample input:
department: 999000-Should really be marketing
Sample output:
"999000","Marketing","999000-Marketing"
The employee_departments.txt has the data in this format:
Department_Name,Number
So it would look like this:
Marketing,999000
I'm executing the script with awk -f script.awk datafile
Any suggestions as to how to best proceed would be greatly appreciated.
Thanks!