Results 1 to 6 of 6
I have a file with similar information: (call it course.txt)
course-name:email-address
course-name:email-address
course-name1:email-address
coursename-2:email-address
course-name2:email-address
and wish to get an output as follows: email-address >> course.txt
so in pseudo code ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-12-2005 #1Just Joined!
- Join Date
- Sep 2005
- Location
- SC
- Posts
- 3
awk redirect problem
I have a file with similar information: (call it course.txt)
course-name:email-address
course-name:email-address
course-name1:email-address
coursename-2:email-address
course-name2:email-address
and wish to get an output as follows: email-address >> course.txt
so in pseudo code I would have:
awk -F: '{print $2}' >> "{print $1}' course.txt
however, this doesn't work in real life. How do I get the redirection?
- 09-12-2005 #2
Can you explain exactly what you're trying to do? I'm not following.
- 09-13-2005 #3Just Joined!
- Join Date
- Sep 2005
- Location
- SC
- Posts
- 3
The output of a database query gives me a course name, and an email address of a student on each line. There may be 3 students in a particular course name (course number and section are incorporated in the course name) or as many as 180 students. The query will give me information from all courses offered and email addresses of the students in that class.
What I am trying to do is to get that information broken down to a new file per class with only that class's email addresses in it.
The example file shows what the colon delimited info I am given to work this magic. I thought that, very simply, since the first argument is the class name, that a redirected output file could be made with the name of ($0) and that the email address ($1), could be appended to that text file.
- 09-13-2005 #4
Ok, I think I got it. So in the situation where source rows are:
-----------------------
ENG101:joe@some.com:deb@some.com
SCI101:kim@some.com
ALG101:naomi@some.com:shiniqua@some.com:louey@some .com
-----------------------
you would wind up with three files.
1. ENG101.txt, which contains the lines:
joe@ some.com
deb@ some.com
2. SCI101.txt, which contains the line:
kim@ some.com
3. ALG101.txt, which contains the lines:
naomi@ some.com
shiniqua@ some.com
louey@ some.com
Correct? This is your goal?
- 09-13-2005 #5Just Joined!
- Join Date
- Sep 2005
- Location
- SC
- Posts
- 3
That is correct EXCEPT that each line only contains:
course-name:email-address
but in essence you are correct in my goal. So, using your excellent data, the file would be:
ENG101:joe@some.com
ENG101:deb@some.com
SCI101:kim@some.com
ALG101:naomi@some.com
ALG01:shiniqua@some.com
ALG01:louey@some.com
ALG02:dewey@some.com
- 09-13-2005 #6
Ok, no problem. Here is what you can do:
Tested and verified.Code:awk -F : '{ print $2 >> $1 }' data-file


Reply With Quote
