Using loop command in UNIX for converting column to row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using loop command in UNIX for converting column to row
# 1  
Old 04-09-2015
Using loop command in UNIX for converting column to row

Dear folks

I have 300 files which one of them are looking like:

Code:
1.SNP
0
0
1
0

I am looking for desire output:

Code:
1.SNP 0 0 1 0

I used this below command to run all of the 300 file at the same time


Code:
for file in *.SNP; do awk '{printf( "%s ", $1 );} END {printf("\n");}' $file > "$(basename "$file" .SNP).gen"; done

But I do not know why all of the *.gen file do not include any information in the *.gen files. Could anyone give me a guide for this problem?

Last edited by Scott; 04-09-2015 at 07:14 PM.. Reason: Code tags, please. We've asked you many-a-time.
# 2  
Old 04-09-2015
There isn't anything immediately obvious wrong with your script...

What operating system are you using?

What shell are you using?

Do you get any output at all when you run your script?

Is a .gen file created for each .SNP file in the directory in which you run this loop?

Pick one of your input files and show us the output (in CODE tags) from the commands:
Code:
ls -l "file.SNP"
od -bc "file.SNP"
awk '{printf( "%s ", $1 );} END {printf("\n");}' "file.SNP" > "$(basename "file.SNP" .SNP).gen"
ls -l "file.gen"
od -bc "file.gen"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unique values in a row sum the next column in UNIX

Hi would like to ask you guys any advise regarding my problem I have this kind of data file.txt 111111111,20 111111111,50 222222222,70 333333333,40 444444444,10 444444444,20 I need to get this file1.txt 111111111,70 222222222,70 333333333,40 444444444,30 using this code I can... (6 Replies)
Discussion started by: reks
6 Replies

2. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

3. Shell Programming and Scripting

converting column to row

Hi everyone.. I have a list of values in a file... 1.2345e-1 2.282828e+ 3.2341e-1 1.1223445e-1 I am interested in converting this column to a row.. 1.2345e-1 2.282828e+ 3.2341e-1 1.1223445e-1 can anyone pls help?? I am a liunx newbie.. Thanks.. (7 Replies)
Discussion started by: kjha
7 Replies

4. Shell Programming and Scripting

command for converting 4 column data to 1 column

dear friends I want to convert four column data to one column data. For example: from 1, 2, 3, 4 5, 6, 7, 8to 1 2 3 4 5 6 7 8what is the general command for that type of convertion. thanks (5 Replies)
Discussion started by: rpf
5 Replies

5. Shell Programming and Scripting

extracting row with max column value using awk or unix

Hello, BC106081_abc_128240811_128241377 7.96301 BC106081_abc_128240811_128241377 39.322 BC106081_cde_128240811_128241377 1.98628 BC106081_def_128240811_128241377 -2.44492 BC106081_abc_128240811_128241377 69.5504 FLJ00075_xyz_14406_16765 -0.173417 ... (3 Replies)
Discussion started by: Diya123
3 Replies

6. Shell Programming and Scripting

Converting Multiple rows to Single Row using unix commands

Can somebody help me in solving this.. Input data is like 0 A 1 B 2 C 3 D 0 A1 1 B1 2 C1 3 D1 0 A2 1 B2 2 C2 3 D2 Output should be like A B C D A1 B1 C1 D1 A2 B2 C2 D2 (7 Replies)
Discussion started by: Mahantesh Patil
7 Replies

7. Shell Programming and Scripting

Help converting column to row for multiple files

Hi all, I am pretty new at this so be gentle. Also, if there is any chance you could explain what the code you use is actually doing, that would really help me out, Im learning after all :) So I am trying to convert a selected column of numbers from input file1 into a row in output file2 ... (3 Replies)
Discussion started by: StudentServitor
3 Replies

8. Shell Programming and Scripting

Converting values in a ROW to COLUMN

Hi All, I needd to convert values in a row to a column. eg: Input is as: value1,value2,value3,value4,.........,value N Required Output: Value1 Value2 Value3 . . . Value N Please help.... (3 Replies)
Discussion started by: sambaman
3 Replies

9. Shell Programming and Scripting

updating a column in a unix table for a particular row

Hi, I have the following requirement. I have a unix table as below progname par1 par2 par3 par4 PROG1 abc def 0012 ooo PROG2 wed xas 0100 xxx PROG3 kkk ppp 0004 ppp Different programs(ex:PROG1,PROG2..) accesses this table and update... (5 Replies)
Discussion started by: thanuman
5 Replies

10. Shell Programming and Scripting

Converting Column values to comma delimted single Row

I have a requirement in which i have to read a file which has multiple columns seperated by a pipe "|" from this i have to read each column values seperately and create a comma seperated row for the column and write to another file. eg: Input file: ColA ColB 1 2 2 x 3 y... (5 Replies)
Discussion started by: nvuradi
5 Replies
Login or Register to Ask a Question