Entering edit mode
6.9 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