append to two files

I tried to write a script ( not working) to append first value from mylist to a file called my myfirstResult and to another called mysecondResult

 
awk ' {print $1} >> myfirsResult  ' < mylist
awk ' {print $1} >> mysecondResult  ' < mylist
 
$ cat mylist
 
A 02/16/2012
B 02/19/2012
C 02/20/2012
D 02/17/2012
E 02/16/2012
 

I need to append values to two files as following:

 
$ cat myfirsResult
 
A
B
C
D
E

and to another file mysecondResult with no new lines

 
$ cat mysecondResult
A B C D E

Thanks , Sara

In both cases you should put the '>> outputfile' part outside of awk, after everything else.

That should allow your first awk statement to work.

For the second, perhaps

awk -v RS=" " '{ print $1 } END { printf("\n"); }' inputfile >>outputfile
1 Like
awk '{print $1}' mylist >> myfirsResult
awk '{printf "%s ", $1}' mylist >> mysecondResult

If you are going to append more from another file

awk '{print "%s ", $1} END{printf "\n"}' mylist >> mysecondResult 
1 Like
awk '{print $1}' mylist | tee -a myfirstresult | xargs >> mysecondresult