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_ECMA基本语法中的几种封装的小函数-1
    DOM_06之定时器、事件、cookie
    DOM_05之DOM、BOM常用对象
    OC数组中文排序
    uiwebview加载中文URL
    ios判断点击的坐标点
    获取字符串在另一个字符串中出现的次数
    NSFileHandle
    NSFileManager
    NSData
  • 原文地址:https://www.cnblogs.com/foreverycc/p/3092183.html
Copyright © 2011-2022 走看看