根据列值复制或复制行

时间:2016-08-09 02:07:37

标签: unix command-line bioinformatics

我想要一个6列(约130万行)文件,并根据第4列中的值复制这些行。输入:

public function simpanberkas()
    {
        $key = $this->uri->segment(3);
        $this->load->model('model_pengaduan');
        $query = $this->model_pengaduan->getdata($key);
        if($query->num_rows>0)
        {
            foreach ($query->result() as $row) {
                $data['file'] = $row->file;
            }
        }

        $config['upload_path'] = './assets/file/';
        $config['allowed_types'] = 'pdf|doc|docx|excel';
        $config['max_size'] = '1000';
        //$config['max_width']  = '2000';
        //$config['max_height']  = '1024';
         $this->load->library('upload',$config);
         //$this->upload->initialize($config);
         //$berkas = $this->input->post('berkas');
            if(!$this->upload->do_upload('berkas')){
                    $error = array('error' => $this->upload->display_errors());
                    $this->session->set_flashdata('info',$error['error']);
            }else{
                    $file_data=$this->upload->data();
                    $data['file']=base_url().'/assets/file/'.$file_data['file_name'];
            }

            $this->model_pengaduan->getupdate($key,$data);
            redirect('pengaduan');      
    }

输出:

chr1    6209    6234    2   255 +
chr1    6686    6710    1   255 +
chr1    6755    6780    3   255 +

我发现this question非常相似,但当我尝试使用代码时,我无法维护我的列:

请原谅我的脚本无知。任何建议都表示赞赏。

1 个答案:

答案 0 :(得分:6)

awk救援!

$ awk '{c=$4; while(c-->0) print}' file

chr1 6209 6234 2 255 +
chr1 6209 6234 2 255 +
chr1 6686 6710 1 255 +
chr1 6755 6780 3 255 +
chr1 6755 6780 3 255 +
chr1 6755 6780 3 255 +