|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Merge files with file names added
I want to merge several files with identical format: file 1: Code:
rs3094315 0.0006105222804 0.9528743638 rs3131972 -0.05461465109 0.3139864854 rs3115860 -0.06041530955 0.3195499498 file 2: Code:
rs2073813 -0.06039552152 0.2956527097 rs11564776 -0.1864266568 0.1976612108 rs12562034 0.00225669783 0.8555456823 rs12124819 -0.05026905981 0.2383563616 ... For each file, they have a unique name as XX1.phe.ps. XX1.phe.ps I want to merge all the files AND, add part of the file name "XXX" to the first column. So the expected output is: Code:
XX1 rs3094315 0.0006105222804 0.9528743638 XX1 rs3131972 -0.05461465109 0.3139864854 XX1 rs3115860 -0.06041530955 0.3195499498 XX2 rs2073813 -0.06039552152 0.2956527097 XX2 rs11564776 -0.1864266568 0.1976612108 XX2 rs12562034 0.00225669783 0.8555456823 XX2 rs12124819 -0.05026905981 0.2383563616 How can I do this?
Last edited by radoulov; 01-04-2013 at 03:49 PM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
printf "%s\n" *.phe.ps | awk -F"." '{ file=$0; pre=sprintf("%s",$1); while(( getline line < file ) > 0 ) { print pre,line; } }' |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
luoruicd (01-07-2013) | ||
| Sponsored Links | ||
|
|
#5
|
||||
|
||||
|
mukulverma2408, your code is good for requester with some minor changes: Code:
awk '{ split(FILENAME,A,"."); print A[1],$0; } ' *.phe.ps |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
luoruicd (01-07-2013) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Merge two files into one file | chiru_h | Shell Programming and Scripting | 1 | 01-19-2012 12:28 AM |
| merge files along with file names (awk)? | wei.deng | UNIX for Dummies Questions & Answers | 5 | 11-04-2011 04:49 PM |
| Merge files from /etc to one file using C | sussil | Programming | 2 | 06-26-2010 10:45 AM |
| Merge two files whose names are given in other file | harshada | Shell Programming and Scripting | 1 | 10-01-2008 04:17 AM |
| merge two files in one file | nvkuriseti | Shell Programming and Scripting | 3 | 08-27-2007 06:06 AM |
|
|