Concatenate two columns and separate by - (minus)


 
Thread Tools Search this Thread
# 8  
If the columns of the input file are fixed, here's a very basic approach:

Code:
awk '{print $1" "$2" "$3" "$1"-"$3}' file

1 rs1111 10583 1-10583
1 rs1891 10611 1-10611
1 rs1807 13302 1-13302

# 9  
i gor this output
Code:
CHR     SNP     BP      A1      A2      MAF     NCHROBS PrimaryFirst^M CHR-PrimaryFirst
1       rs58108140      10583   A       G       .1438   2184    0^M 1-0
1       rs189107123     10611   G       C       .01877  2184    1^M 1-1
1       rs180734498     13302   T       C       .114    2184    1^M 1-1

still not my wanted output

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.


---------- Post updated at 10:03 AM ---------- Previous update was at 10:00 AM ----------

Quote:
Originally Posted by in2nix4life
If the columns of the input file are fixed, here's a very basic approach:

Code:
awk '{print $1" "$2" "$3" "$1"-"$3}' file

1 rs1111 10583 1-10583
1 rs1891 10611 1-10611
1 rs1807 13302 1-13302

yes they are fixed
thanks
# 10  
First off, please start using code tags when posting code/data samples - you've already been warned at least once.
Second off, looks looks like you have ^M-s in your file - if so, get rid of them.
Thirdly, given your sample data of:
Code:
1       rs58108140      10583   A       G       .1438   2184    0
1       rs189107123     10611   G       C       .01877  2184    1
1       rs180734498     13302   T       C       .114    2184    1

what's the desired output?
# 11  
with
Code:
awk '{print $1" "$2" "$3" "$1"-"$3}'

works perfect thanks but how to keep the other colomns in the file (4, 5 ,..)?
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 11-05-2012 at 11:09 AM.. Reason: once AGAIN - use code tags!!!
# 12  
ok, you should have posted the REAL data to beginn with... Try:
Code:
awk '{print $0, $1 "-" $3}' myFile

# 13  
Quote:
Originally Posted by vgersh99
First off, please start using code tags when posting code/data samples - you've already been warned at least once.
Second off, looks looks like you have ^M-s in your file - if so, get rid of them.
Thirdly, given your sample data of:
Code:
1       rs58108140      10583   A       G       .1438   2184    0
1       rs189107123     10611   G       C       .01877  2184    1
1       rs180734498     13302   T       C       .114    2184    1

what's the desired output?
okay sorry thanks

the desired out put is:
1 rs58108140 10583 A G .1438 2184 0 1-10583
1 rs189107123 10611 G C .01877 2184 1 1-10611
1 rs180734498 13302 T C .114 2184 1 1-13302
# 14  
I'm closing this thread till the OP starts using the code tags and starts following the forum rules.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Mathematics
Difficulty: Easy
The 'Squaring the Circle' problem is solvable.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use "awk" to print columns from different files in separate columns?

Hi, I'm trying to copy and paste the sixth column from a bunch of files into a single file having each column pasted in separate columns (and not one after each other in just one column.) I tried this code but works only partially because it copied and pasted 50 rows of each column... (6 Replies)
Discussion started by: Frastra
6 Replies

2. Shell Programming and Scripting

Separate columns into different text files

Hi I have large text file consisting of five columns. Sample of the file is give below: ed 2-4 12.0 commons that they depended on. मानवों नष्ट किया जिन पर वो आधारित थे। ed 3-1 12.0 Almost E, but would be over. रचना करीब करीब ई तक जाती है, मगर तब तो नाटक ख़त्म हो... (2 Replies)
Discussion started by: my_Perl
2 Replies

3. Shell Programming and Scripting

Concatenate two columns in a file

Hi i am having one requirement like to concatenate two columns in to one columns, can any one help on this please sample scenario i am placing below COL1,COL2,COL3,COL4 1,A,B,C,D 2,e,f,g,h ouput should be 3 columns like below. COL1,COL2,newcolumns 1,A,B,CD 2,e,f,gh ... (9 Replies)
Discussion started by: bhaskar v
9 Replies

4. Shell Programming and Scripting

How to concatenate 2-columns by 2 -columns for a text file?

Hello, I want to concatenate 2-columns by 2-columns separated by colon. How can I do so? For example, I have a text file containing 6 columns separated by tab. I want to concatenate column 1 and 2; column 3 and 4; column 5 and 6, respectively, and put a colon in between. input file: 1 0 0 1... (10 Replies)
Discussion started by: huiyee1
10 Replies

5. Shell Programming and Scripting

Grouping multiple columns and concatenate

I have a CSV file that goes like this: Name,Group,Email Max,Group1,max@.com Dan,Group2,dan@.com Max,Group3,max@.com Max,Group4,max@.com Dan,Group5,dan@.com Jim,Group6,jim@.comBasically my desired output should be: Name,Group,Email Max,Group1|Group3|Group4,max@.com... (6 Replies)
Discussion started by: jeffreybsu
6 Replies

6. Shell Programming and Scripting

Separate into columns

Hi all I have following kind of data in a file but non separated ESR1 PA156 leflunomide PA450192 CHST3 PA26503 docetaxel tungstate Pa4586; thalidomide Pa34958; I want to separate entries into columns so that I can put into excel sheet in proper arrangement. I want entries... (4 Replies)
Discussion started by: manigrover
4 Replies

7. Shell Programming and Scripting

Comparing columns in two separate files

Hey all, I have a file structure that looks something like this: file1 306708278 88954535 234167885 file2 2012-03-27T12:32:56+00:00 137 Orchotorena 184616310003601409 306708278 es 40.4777947 Majadahonda -3.6416896333333333 0 false atlante83 "<a href=""http://tapbots.com/tweetbot""... (8 Replies)
Discussion started by: dgaff
8 Replies

8. Shell Programming and Scripting

Concatenate columns from multiple files

Hi all, I want the 2nd column of every file in the directory in a single file with the file name as column header. $cat file1.txt a b c d e f $cat file2.txt f g h g h j $cat file3.txt a b d f g h (2 Replies)
Discussion started by: newbie83
2 Replies

9. Shell Programming and Scripting

Concatenate columns from files

Hi, I have a file1.txt like this: and a file2.txt like this: I wat only append file2.txt to file1.txt and to have something like this: How could i do ? (2 Replies)
Discussion started by: AdminLew
2 Replies

10. Shell Programming and Scripting

concatenate 'n' number of columns in a file

i have a file which may have 'n' number of columns 1 222 fafda 32 afdaf 4343 4343 234 43fdaf 4343 fdd fdfd fdfd fdd fdfd fdfd fdfd fdfd fdfd fdd fdfd fdfd need to concatenate the columns with... (3 Replies)
Discussion started by: mlpathir
3 Replies

Featured Tech Videos