Please note that as a programmer I cannot tell the file format or details of my production files so I have re-framed my file and taken a case of departments. Kindly guide as its related to a production requirement of data containing recors of production customer NOT A HOMEWORK
I have a file containing details of different departments . Infomration of departments is in various tags
file is as below
DEPTNUM 1|
FACULTY 20|
STUDENTS 300|
COURSES 3|
DEPTNUM 2|
FACULTY 25|
STUDENTS 500|
COURSES 30|
DEPTNUM 3|
FACULTY 22|
STUDENTS 600|
COURSES 31|
AND SO ON
I want to create a new file from the above file which should contain only two fields belonging to one department
format
DEPTNUM,STUDENTS
1,50
2,500
3,600
There are multiple files containing department details of individiual college
I tried below
for file in `ls -1 pwd`
do
var1=`grep DEPTNUM $file |cut -c 9`
var2=`grep STUDENTS $file |cut -c 10-12`
done
However it did not serve my purpose and not giving expected result
I am facing another issue in the approach . I have new file structure like dummy exmaple below
DEPT 1|
DEPTNAME Science|
FACULTY 20|
STUDENTS 300|
COURSES 3|
DEPT 2|
DEPTNAME Humanities|
FACULTY 25|
STUDENTS 500|
COURSES 30|
DEPT 3|
DEPTNAME Engineering|
FACULTY 22|
STUDENTS 600|
COURSES 31|
AND SO ON
I want to get o/p like below
DEPT,STUDENTS,FACULTY
But as DEPTNAME is coming after DEPT in the input file the awk approach is matching DEPTNAME instead of DEPT .
Please guide