[Solved] Splitting comma set files

This might work for you (GNU sed): sed -r ‘s/^(.*\|.*\|)([^,]*),([^|]*)(\|.*\|.*\|)([^,]*),([^|]*)(.*)/\1\2\4\5\7\n\1\3\4\6\7/;P;D’ file Iteratively split the current line into pieces, building two lines separated by a newline. The first line contains the head of the 3rd and 6th fields, the second line contain the tails of the 3rd and 6th lines. Print then delete the first of … Read more

[Solved] Rearrange and delete fields with sed

You can use the following sed command, let me know if you need additional explanations about it: sed -E -i.bak ‘s/^([^\s]*)\s+([^,]*),[^,]*,\s*([^\s]*)\s+([^\s]*)\s*$/\4:\2:\1:\3/g’ test_add_file.in; TESTED on: In a nutshell, you are define a regex that sed will use to look in your text file to fetch the required patterns, then you use backreferences to reuse the actual … Read more

[Solved] How to lowercase and replace spaces in bash? [closed]

Requires bash4 (tested with 4.3.48). Assuming you never want a upper case character in the value of the variable output, I would propose the following: typeset -l output output=${input// /_} typeset -l output: Defines the variable to be lowercase only. From man bash: When the variable is assigned a value, all upper-case characters are converted … Read more

[Solved] Remove lines from a text file that contains multiple string patterns from another file in linux [closed]

$ cat tst.awk BEGIN { FS = “[\t|]” } NR==FNR { for (i=1; i<=3; i++) { if ($i == “”) { $i = “N.A.” } } a[$1 OFS $2 OFS $3] next } !(($3 OFS $5 OFS $6) in a) $ awk -f tst.awk file1 file2 123|234|aa|ur29842|b|c|234|567 123|234|aa|ur2909842|bb|ccc|234|567 123|234|aaa|ur29042842|bb|cc|234|567 123|234|N.A.|ur2922|bbb|cccc|234|567 0 solved Remove lines from … Read more

[Solved] Replace first occurrence of a pattern if not preceded with another pattern

This might work for you (GNU sed): sed ‘/\<cat\>.*\<bird\>/b;s/\<\(bird\) \+[0-9]\+/\1 0/;T;:a;n;ba’ file If a line contains the word cat before the word bird end processing for that line. Try to substitute the number following the word bird by zero. If not successful end processing for that line. Otherwise read/print all following lines until the end … Read more

[Solved] What does this sed command do? [closed]

That’s not a sed script, it’s a shell script containing bash, sed, and cut commands. The sed script is obfuscated by bad quoting practices, unnecessarily changing the delimiter, and adding an unnecessary argument. I assume you know what cut -f 2 does so I can’t imagine why you included that to further obfuscate your question … Read more

[Solved] XLST – Copy XML tag and replace attribute value [closed]

XSLT based solution. Input XML <config> <connection port=”4404″ type=”tcp”> <selection name=”test-mode” enabled=”true”/> </connection> <connection port=”4405″ type=”tcp”> <selection name=”test-mode” enabled=”true”/> </connection> <connection port=”4406″ type=”tcp”> <selection name=”test-mode” enabled=”true”/> </connection> <option> <maxNumberOfDownloads>10</maxNumberOfDownloads> </option> </config> XSLT <?xml version=”1.0″?> <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”xml” encoding=”utf-8″ indent=”yes” omit-xml-declaration=”yes”/> <xsl:strip-space elements=”*”/> <xsl:template match=”@*|node()”> <xsl:copy> <xsl:apply-templates select=”@*|node()”/> </xsl:copy> </xsl:template> <xsl:template match=”connection[@port]”> <xsl:copy> <xsl:apply-templates … Read more

[Solved] Remove newlines between two words

something like this? kent$ awk ‘/^key.:/{p=1}/^name:/{p=0} {if(p)printf “%s”,$0;else printf “%s%s\n”, (NR==1?””:RS),$0}’ file name: charles key1: howareyou? name: erika key2: I’mfine,thanks name: … handle the spaces: awk ‘/^key.:/{p=1}/^name:/{p=0} {if(p)printf “%s%s”,(/^key.:/?””:” “),$0; else printf “%s%s\n”, (NR==1?””:RS),$0}’ file output: name: charles key1: how are you? name: erika key2: I’m fine, thanks name: … 2 solved Remove newlines between … Read more