zoukankan      html  css  js  c++  java
  • My first bash program

    I didn't realize that bash is so useful until recently. 

    Just a minute before, I'm still a guy who just know some basic linux commands such as: cd, cp, pwd...

    However, from now on, I'll begin to learn shell programming!

    The problem I want to solve is:

    I want to get the first 3 columns of a bunch of ".bed" format files.

    How to solve it?

    First cd to your target directory,

    then type in the following commands

    cut -f1,2,3 $old_filename > new_filename

    however, if you have lots of files, you'll do this one by one, which is troublesome and time consuming!

    So you have to learn to write bash programs!!!

    Here's my first bash program to solve this problem:

    for i in *.bed
    do  
     cut -f1,2,3 $i > $(echo New_$i) 
    done

    *.bed:   represents all the files ends with .bed

    do and done:   are necessary components of a for loop in bash

    cut -f1,2,3 :   cut the first 3 columns of the file

    > :   output the cut files to new ones

    echo New_$i:   concatenate new name of the file

    $:   dollar sign is reallly important. You cannot use 'i' solely to represent the object i. Instead, you have to use '$i' to represent the object!

  • 相关阅读:
    js基础之弹性运动(四)
    js基础之动画(三)
    js基础之动画(二)
    js基础之动画(一)
    js基础之ajax
    js基础之COOKIE
    4.27日软件开发日记我今天做了什么
    4.25日
    4.24日自学成果
    错排公式及其化简
  • 原文地址:https://www.cnblogs.com/foreverycc/p/3092183.html
Copyright © 2011-2022 走看看