LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   decoration of data file (https://www.linuxquestions.org/questions/linux-newbie-8/decoration-of-data-file-4175510754/)

hoi 07-11-2014 01:07 AM

decoration of data file
 
I have a file like:
1 17 0.866
1 18 0.866
1 19 0.866
1 21 0.866
2 17 0.866
2 18 0.866
2 20 0.866
2 22 0.866
3 17 0.866
3 19 0.866
3 23 0.866
3 26 0.866
1 10 1.000
1 11 1.000
2 11 1.000
2 12 1.000
3 15 1.000
3 16 1.000


I want to modify the above file with respect to column three, into two files.
file1:
1 17 18 19 21
2 17 18 20 22
3 20 19 23 26

file2:
1 10 11
2 11 12
3 15 16

kaushalpatel1982 07-11-2014 08:45 AM

There is problem in FILE1 line 3, Output should be :

"3 17 19 23 26" instead of "3 20 19 23 26"


Code:

#!/bin/bash
j=3

i=1
while [ $i -le $j ]
do
        values=`cat file | grep 0.866 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
        echo $i $values >> file1
        i=`expr $i + 1`
done

i=1
while [ $i -le $j ]
do     
        values=`cat file | grep 1.000 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
        echo $i $values >> file2
        i=`expr $i + 1`
done


hoi 07-12-2014 01:08 AM

Quote:

Originally Posted by kaushalpatel1982 (Post 5202276)
There is problem in FILE1 line 3, Output should be :

"3 17 19 23 26" instead of "3 20 19 23 26"


Code:

#!/bin/bash
j=3

i=1
while [ $i -le $j ]
do
        values=`cat file | grep 0.866 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
        echo $i $values >> file1
        i=`expr $i + 1`
done

i=1
while [ $i -le $j ]
do     
        values=`cat file | grep 1.000 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
        echo $i $values >> file2
        i=`expr $i + 1`
done


Thank you Kaushal....


All times are GMT -5. The time now is 04:14 AM.