Mercurial > repos > bgruening > text_processing
comparison replace_text_in_column.xml @ 4:56e80527c482 draft
Uploaded
| author | bgruening |
|---|---|
| date | Wed, 07 Jan 2015 11:10:52 -0500 |
| parents | 7068d1548234 |
| children | 8928e6d1e7ba |
comparison
equal
deleted
inserted
replaced
| 3:7068d1548234 | 4:56e80527c482 |
|---|---|
| 1 <tool id="tp_replace_in_column" name="Replace Text" version="0.1"> | 1 <tool id="tp_replace_in_column" name="Replace Text" version="@BASE_VERSION@.0"> |
| 2 <description>in a specific column</description> | 2 <description>in a specific column</description> |
| 3 <requirements> | 3 <macros> |
| 4 <import>macros.xml</import> | |
| 5 </macros> | |
| 6 <expand macro="requirements"> | |
| 4 <requirement type="package" version="4.1.0">gnu_awk</requirement> | 7 <requirement type="package" version="4.1.0">gnu_awk</requirement> |
| 5 </requirements> | 8 </expand> |
| 9 <version_command>awk --version | head -n 1</version_command> | |
| 6 <command interpreter="sh"> | 10 <command interpreter="sh"> |
| 7 #adapt to awk's quirks - to pass an acutal backslash - two backslashes are required (just like in a C string) | 11 <![CDATA[ |
| 12 ##adapt to awk's quirks - to pass an acutal backslash - two backslashes are required (just like in a C string) | |
| 8 REPLACE_PATTERN=\${$replace_pattern//\\/\\\\}; | 13 REPLACE_PATTERN=\${$replace_pattern//\\/\\\\}; |
| 9 awk -v OFS="\t" --re-interval --sandbox "{ \$$column = gensub( /$find_pattern/, \"$replace_pattern\", \"g\", \$$column ) ; print \$0 ; }" "$input" > "$output" | 14 awk |
| 15 -v OFS="\t" | |
| 16 --re-interval | |
| 17 --sandbox "{ \$$column = gensub( /$find_pattern/, \"$replace_pattern\", \"g\", \$$column ) ; print \$0 ; }" | |
| 18 "$infile" | |
| 19 > "$output" | |
| 20 ]]> | |
| 10 </command> | 21 </command> |
| 11 <inputs> | 22 <inputs> |
| 12 <param format="tabular" name="input" type="data" label="File to process" /> | 23 <param format="tabular" name="infile" type="data" label="File to process" /> |
| 13 <param name="column" label="in column" type="data_column" data_ref="input" accept_default="true" /> | 24 <param name="column" label="in column" type="data_column" data_ref="infile" accept_default="true" /> |
| 14 | 25 |
| 15 <param name="find_pattern" type="text" size="20" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " > | 26 <param name="find_pattern" type="text" size="20" label="Find pattern" help="Use simple text, or a valid regular expression (without backslashes // ) " > |
| 16 <sanitizer> | 27 <sanitizer> |
| 17 <valid initial="string.printable"> | 28 <valid initial="string.printable"> |
| 18 <remove value="'"/> | 29 <remove value="'"/> |
| 19 </valid> | 30 </valid> |
| 20 </sanitizer> | 31 </sanitizer> |
| 21 </param> | 32 </param> |
| 22 | |
| 23 <param name="replace_pattern" type="text" size="20" label="Replace with" help="Use simple text, or & (ampersand) and \\1 \\2 \\3 to refer to matched text. See examples below." > | 33 <param name="replace_pattern" type="text" size="20" label="Replace with" help="Use simple text, or & (ampersand) and \\1 \\2 \\3 to refer to matched text. See examples below." > |
| 24 <sanitizer> | 34 <sanitizer> |
| 25 <valid initial="string.printable"> | 35 <valid initial="string.printable"> |
| 26 <remove value="'"/> | 36 <remove value="'"/> |
| 27 </valid> | 37 </valid> |
| 28 </sanitizer> | 38 </sanitizer> |
| 29 </param> | 39 </param> |
| 30 | |
| 31 </inputs> | 40 </inputs> |
| 41 <outputs> | |
| 42 <data format="input" name="output" metadata_source="infile" /> | |
| 43 </outputs> | |
| 32 <tests> | 44 <tests> |
| 33 <test> | 45 <test> |
| 34 <param name="input" value="replace_text_in_column_in1.txt" ftype="tabular" /> | 46 <param name="infile" value="replace_text_in_column_in1.txt" ftype="tabular" /> |
| 47 <param name="column" value="4" /> | |
| 48 <param name="find_pattern" value=".+_(R.)" /> | |
| 49 <param name="replace_pattern" value="\1" /> | |
| 35 <output name="output" file="replace_text_in_column_output1.txt" /> | 50 <output name="output" file="replace_text_in_column_output1.txt" /> |
| 36 <param name="column" value="4" /> | |
| 37 <param name="url_paste" value=".+_(R.)" /> | |
| 38 <param name="file_data" value="\1" /> | |
| 39 </test> | 51 </test> |
| 40 </tests> | 52 </tests> |
| 41 <outputs> | |
| 42 <data format="input" name="output" metadata_source="input" /> | |
| 43 </outputs> | |
| 44 <help> | 53 <help> |
| 45 | 54 <![CDATA[ |
| 46 **What it does** | 55 **What it does** |
| 47 | 56 |
| 48 This tool performs find & replace operation on a specified column in a given file. | 57 This tool performs find & replace operation on a specified column in a given file. |
| 49 | 58 |
| 50 .. class:: infomark | 59 .. class:: infomark |
| 70 **Examples of Replace Patterns** | 79 **Examples of Replace Patterns** |
| 71 | 80 |
| 72 - **WORLD** The word 'WORLD' will be placed whereever the find pattern was found. | 81 - **WORLD** The word 'WORLD' will be placed whereever the find pattern was found. |
| 73 - **FOO-&-BAR** Each time the find pattern is found, it will be surrounded with 'FOO-' at the begining and '-BAR' at the end. **&** (ampersand) represents the matched find pattern. | 82 - **FOO-&-BAR** Each time the find pattern is found, it will be surrounded with 'FOO-' at the begining and '-BAR' at the end. **&** (ampersand) represents the matched find pattern. |
| 74 - **\\1** The text which matched the first parenthesis in the Find Pattern. | 83 - **\\1** The text which matched the first parenthesis in the Find Pattern. |
| 75 | |
| 76 | |
| 77 | 84 |
| 78 | 85 |
| 79 ----- | 86 ----- |
| 80 | 87 |
| 81 **Example 1** | 88 **Example 1** |
| 122 - **\|** Separates alternate possibilities. | 129 - **\|** Separates alternate possibilities. |
| 123 | 130 |
| 124 | 131 |
| 125 **Note**: AWK uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported. | 132 **Note**: AWK uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported. |
| 126 | 133 |
| 134 @REFERENCES@ | |
| 135 ]]> | |
| 127 </help> | 136 </help> |
| 128 </tool> | 137 </tool> |
