root/galaxy-central/tools/unix_tools/remove_ending.sh

リビジョン 3, 1.4 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

  • 属性 svn:executable の設定値 *
行番号 
1#!/bin/sh
2
3# Version 0.1 ,  15aug08
4# Written by Assaf Gordon (gordon@cshl.edu)
5#
6
7LINES="$1"
8INFILE="$2"
9OUTFILE="$3"
10
11if [ "$LINES" == "" ]; then
12        cat >&2 <<EOF
13Remove Ending Lines
14
15Usage: $0 LINES [INFILE] [OUTFILE]
16
17   LINES - number of lines to remove from the end of the file
18   [INFILE] - input file (if not specified - defaults to STDIN)
19   [OUTFILE]- output file (if not specified - defaults to STDOUT)
20
21Input Example:
22
23#Chr    Start   End
24chr1    10      15
25chr1    40      20
26chr1    21      14
27total   3 chromosomes
28
29Removing 1 line (the last line) produces:
30
31#Chr    Start   End
32chr1    10      15
33chr1    20      40
34chr     14      21
35
36Usage Example:
37   
38   \$ $0 1 < my_input_file.txt > my_output_file.txt
39
40EOF
41       
42        exit 1
43fi
44
45#Validate line argument - remove non-digits characters
46LINES=${LINES//[^[:digit:]]/}
47
48#Make sure the line strings isn't empty
49#(after the regex above, they will either contains digits or be empty)
50if [ -z "$LINES" ]; then
51        echo "Error: bad line value (must be numeric)" >&2
52        exit 1
53fi
54
55# Use default (stdin/out) values if infile / outfile not specified
56[ -z "$INFILE" ] && INFILE="/dev/stdin"
57[ -z "$OUTFILE" ] && OUTFILE="/dev/stdout"
58
59#Make sure the input file (if specified) exists.
60if [ ! -r "$INFILE" ]; then
61        echo "Error: input file ($INFILE) not found!" >&2
62        exit 1
63fi
64
65
66# The "gunzip -f" trick allows
67# piping a file (gzip or plain text, real file name or "/dev/stdin") to sed
68gunzip -f <"$INFILE" | sed -n -e :a -e "1,${LINES}!{P;N;D;};N;ba" > "$OUTFILE"
69
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。