|
0
|
1 <tool id="unixtools_sed_tool" name="Text transformation" version="0.1.1">
|
|
|
2 <description>with sed</description>
|
|
|
3 <requirements>
|
|
|
4 <requirement type="package" version="4.2.2-sandbox">gnu_sed</requirement>
|
|
|
5 </requirements>
|
|
|
6 <command>
|
|
|
7 sed --sandbox -r $silent -f '$sed_script' '$input' > '$output'
|
|
|
8 </command>
|
|
|
9 <inputs>
|
|
|
10 <param format="txt" name="input" type="data" label="File to process" />
|
|
|
11
|
|
|
12 <param name="url_paste" type="text" area="true" size="5x35" label="SED Program" help="">
|
|
|
13 <sanitizer>
|
|
|
14 <valid initial="string.printable">
|
|
|
15 <remove value="'"/>
|
|
|
16 </valid>
|
|
|
17 </sanitizer>
|
|
|
18 </param>
|
|
|
19
|
|
|
20 <param name="silent" type="select" label="operation mode" help="(Same as 'sed -n', leave at 'normal' unless you know what you're doing)" >
|
|
|
21 <option value="">normal</option>
|
|
|
22 <option value="-n">silent</option>
|
|
|
23 </param>
|
|
|
24
|
|
|
25 </inputs>
|
|
|
26 <configfiles>
|
|
|
27 <configfile name="sed_script">
|
|
|
28 $url_paste
|
|
|
29 </configfile>
|
|
|
30 </configfiles>
|
|
|
31 <tests>
|
|
|
32 <test>
|
|
|
33 <param name="input" value="unix_sed_input1.txt" />
|
|
|
34 <output name="output" file="unix_sed_output1.txt" />
|
|
|
35 <param name="url_paste" value="1d ; s/foo/bar/" />
|
|
|
36 <param name="silent" value="" />
|
|
|
37 </test>
|
|
|
38 <test>
|
|
|
39 <param name="input" value="unix_sed_input1.txt" />
|
|
|
40 <output name="output" file="unix_sed_output2.txt" />
|
|
|
41 <param name="url_paste" value="/foo/ { s/foo/baz/g ; p }" />
|
|
|
42 <param name="silent" value="silent" />
|
|
|
43 </test>
|
|
|
44 </tests>
|
|
|
45 <outputs>
|
|
|
46 <data format="input" name="output" metadata_source="input" />
|
|
|
47 </outputs>
|
|
|
48 <help>
|
|
|
49
|
|
|
50 **What it does**
|
|
|
51
|
|
|
52 This tool runs the unix **sed** command on the selected data file.
|
|
|
53
|
|
|
54 .. class:: infomark
|
|
|
55
|
|
|
56 **TIP:** This tool uses the **extended regular** expression syntax (same as running 'sed -r').
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60 **Further reading**
|
|
|
61
|
|
|
62 - Short sed tutorial (http://www.linuxhowtos.org/System/sed_tutorial.htm)
|
|
|
63 - Long sed tutorial (http://www.grymoire.com/Unix/Sed.html)
|
|
|
64 - sed faq with good examples (http://sed.sourceforge.net/sedfaq.html)
|
|
|
65 - sed cheat-sheet (http://www.catonmat.net/download/sed.stream.editor.cheat.sheet.pdf)
|
|
|
66 - Collection of useful sed one-liners (http://student.northpark.edu/pemente/sed/sed1line.txt)
|
|
|
67
|
|
|
68 -----
|
|
|
69
|
|
|
70 **Sed commands**
|
|
|
71
|
|
|
72 The most useful sed command is **s** (substitute).
|
|
|
73
|
|
|
74 **Examples**
|
|
|
75
|
|
|
76 - **s/hsa//** will remove the first instance of 'hsa' in every line.
|
|
|
77 - **s/hsa//g** will remove all instances (beacuse of the **g**) of 'hsa' in every line.
|
|
|
78 - **s/A{4,}/--&--/g** will find sequences of 4 or more consecutive A's, and once found, will surround them with two dashes from each side. The **&** marker is a place holder for 'whatever matched the regular expression'.
|
|
|
79 - **s/hsa-mir-([^ ]+)/short name: \\1 full name: &/** will find strings such as 'hsa-mir-43a' (the regular expression is 'hsa-mir-' followed by non-space characters) and will replace it will string such as 'short name: 43a full name: hsa-mir-43a'. The **\\1** marker is a place holder for 'whatever matched the first parenthesis' (similar to perl's **$1**) .
|
|
|
80
|
|
|
81
|
|
|
82 **sed's Regular Expression Syntax**
|
|
|
83
|
|
|
84 The select tool searches the data for lines containing or not containing a match to the given pattern. A Regular Expression is a pattern descibing a certain amount of text.
|
|
|
85
|
|
|
86 - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for.
|
|
|
87 - **^** matches the beginning of a string(but not an internal line).
|
|
|
88 - **(** .. **)** groups a particular pattern.
|
|
|
89 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern.
|
|
|
90
|
|
|
91 - **{n}** The preceding item is matched exactly n times.
|
|
|
92 - **{n,}** The preceding item ismatched n or more times.
|
|
|
93 - **{n,m}** The preceding item is matched at least n times but not more than m times.
|
|
|
94
|
|
|
95 - **[** ... **]** creates a character class. Within the brackets, single characters can be placed. A dash (-) may be used to indicate a range such as **a-z**.
|
|
|
96 - **.** Matches any single character except a newline.
|
|
|
97 - ***** The preceding item will be matched zero or more times.
|
|
|
98 - **?** The preceding item is optional and matched at most once.
|
|
|
99 - **+** The preceding item will be matched one or more times.
|
|
|
100 - **^** has two meaning:
|
|
|
101 - matches the beginning of a line or string.
|
|
|
102 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets.
|
|
|
103 - **$** matches the end of a line or string.
|
|
|
104 - **\|** Separates alternate possibilities.
|
|
|
105
|
|
|
106
|
|
|
107 **Note**: SED uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported.
|
|
|
108
|
|
|
109 </help>
|
|
|
110 </tool>
|