Mercurial > repos > bgruening > text_processing
view sed.xml @ 21:86755160afbf draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/text_processing/text_processing commit c2b1677d1c94433f777c2dc28ac8eec0a99cc6a7
author | bgruening |
---|---|
date | Fri, 16 Aug 2024 10:41:54 +0000 |
parents | 12615d397df7 |
children |
line wrap: on
line source
<tool id="tp_sed_tool" name="Text transformation" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="@PROFILE@"> <description>with sed</description> <macros> <import>macros.xml</import> </macros> <expand macro="creator"/> <requirements> <requirement type="package" version="4.8">sed</requirement> </requirements> <version_command>sed --version | head -n 1</version_command> <command> <![CDATA[ sed --sandbox -r #if $adv_opts.adv_opts_selector == 'advanced': $adv_opts.silent #end if -f '$sed_script' '$infile' > '$output' ]]> </command> <configfiles> <configfile name="sed_script"> $code </configfile> </configfiles> <inputs> <param format="txt" name="infile" type="data" label="File to process" /> <param name="code" type="text" area="true" size="5x35" label="SED Program" help=""> <sanitizer> <valid initial="string.printable"> <remove value="'"/> </valid> </sanitizer> </param> <conditional name="adv_opts"> <param name="adv_opts_selector" type="select" label="Advanced Options"> <option value="basic" selected="True">Hide Advanced Options</option> <option value="advanced">Show Advanced Options</option> </param> <when value="basic" /> <when value="advanced"> <param name="silent" type="select" label="Operation mode" help="Same as 'sed -n', leave at 'normal' unless you know what you're doing." > <option value="">normal</option> <option value="-n">silent</option> </param> </when> </conditional> </inputs> <outputs> <data name="output" format_source="infile" metadata_source="infile" /> </outputs> <tests> <test> <param name="infile" value="sed1.txt" /> <param name="code" value="1d ; s/foo/bar/" /> <param name="silent" value="" /> <output name="output" file="sed_results1.txt" /> </test> <test> <param name="infile" value="sed1.txt" /> <param name="code" value="/foo/ { s/foo/baz/g ; p }" /> <param name="adv_opts_selector" value="advanced" /> <param name="silent" value="-n" /> <output name="output" file="sed_results2.txt" /> </test> </tests> <help> <![CDATA[ **What it does** This tool runs the unix **sed** command on the selected data file. .. class:: infomark **TIP:** This tool uses the **extended regular** expression syntax (same as running 'sed -r'). **Further reading** - Short sed tutorial (http://www.linuxhowtos.org/System/sed_tutorial.htm) - Long sed tutorial (http://www.grymoire.com/Unix/Sed.html) - sed faq with good examples (http://sed.sourceforge.net/sedfaq.html) - sed cheat-sheet (http://www.catonmat.net/download/sed.stream.editor.cheat.sheet.pdf) ----- **Sed commands** The most useful sed command is **s** (substitute). **Examples** - **s/hsa//** will remove the first instance of 'hsa' in every line. - **s/hsa//g** will remove all instances (beacuse of the **g**) of 'hsa' in every line. - **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'. - **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**) . **sed's Regular Expression Syntax** 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. - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for. - **^** matches the beginning of a string(but not an internal line). - **(** .. **)** groups a particular pattern. - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern. - **{n}** The preceding item is matched exactly n times. - **{n,}** The preceding item ismatched n or more times. - **{n,m}** The preceding item is matched at least n times but not more than m times. - **[** ... **]** 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**. - **.** Matches any single character except a newline. - ***** The preceding item will be matched zero or more times. - **?** The preceding item is optional and matched at most once. - **+** The preceding item will be matched one or more times. - **^** has two meaning: - matches the beginning of a line or string. - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets. - **$** matches the end of a line or string. - **\|** Separates alternate possibilities. **Note**: SED uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported. ]]> </help> <expand macro="citations" /> </tool>