Off topic:How to repeat a row for each value of its corresponding column
3
0
Entering edit mode
7.0 years ago
ak93sharma ▴ 20

hello folks , i am not expert in programming , I want to repeat a row for all its corresponding values any help

my input file is like this

pos COL1    COL2    COL3
18691441    C   A   G
18691572    G   C   G
18691620    A   T   G
18691716    C   G   C

i want output like this

pos COL1    
18691441    C   
18691441    A   
18691441    G   
18691572    G   
18691572    C   
18691572    G   
18691620    A   
18691620    T   
18691620    G   
18691716    C   
18691716    G   
18691716    C

i am trying to repeat a row but it simply makes them duplicate , i am using

while read line; do for i in {1..3}; do echo "$line"; done; done < real2.txt

and gives output:

pos COL1    COL2    COL3
18691441    C   A   G
18691441    C   A   G
18691441    C   A   G
18691572    G   C   G
18691572    G   C   G
18691572    G   C   G
18691620    A   T   G
18691620    A   T   G
18691620    A   T   G
18691716    C   G   C
18691716    C   G   C
18691716    C   G   C

then i extracted pos from input 1.txt file and make 1_pos.txt and write something like this:

 pos
18691441
18691572
18691620
18691716
for i in `cat 1_post.txt`;
do
x=$(grep -i "^$i" 1.txt | awk 'FNR == 1 {print $1"\t"$2}' ) ;
y=$(grep -i "^$i" 1.txt | awk 'FNR == 1 {print $1"\t"$3}' ) ;
z=$(grep -i "^$i" 1.txt | awk 'FNR == 1 {print $1"\t"$4}' ) ;
echo -e "$x""\n""$y""\n""$z";
done

this gives me output, without col information:

18691441    C
18691441    A
18691441    G
18691572    G
18691572    C
18691572    G
18691620    A
18691620    T
18691620    G
18691716    C
18691716    G
18691716    C
awk perl linux bash shell • 1.2k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1818 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6