Tag Info

New answers tagged

0

egrep -v ^'(#|$)' file.txt Strips all comments and empty lines from file.txt


4

I assume that the string can contain any character except newlines and null bytes. You can quote the string for use as a sed pattern. The characters $*./[\^ need to be preceded by a backslash. In the replacement text, you need to quote the characters \&/. regexp=$(printf %s "$old" | sed 's:[$*./\[^]:\\&:g') replacement=$(printf %s "$new" | sed ...


0

Yes, you should be able to use the -f option to specify a file containing a [list of] expression[s] -f script-file, --file=script-file add the contents of script-file to the commands to be executed However you will still need to escape any special characters (AFAIK there is no sed equivalent of grep's --fixed-strings) - if perl is available ...


1

It's not supposed to work on apt-get upgrade. The reason is that it's not a straight-forward upgrade. In this case, apt has to remove package_a and install package_b for it to do an "upgrade", and apt will only do direct upgrades (new version of an installed package and any additional dependencies installed) when running apt-get upgrade. apt-get ...


1

You shouldn't use something like sed/awk for it and use an xml/xslt processor, such as xmlstarlet instead. Create an xslt file with a template such as and save it under transform.xsl: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="@*|node()"> ...


-1

Do it as you prefer but here it is: STR='<tag name="abc"></tag>' AUX=$(echo $STR | cut -d"\"" -f2) echo $STR | sed "s/tag/$AUX/g"


3

You could also use perl, which should support \b on all platforms. Assuming your list of replacements is in the format you show (separated by ->), you could do: perl -F"->" -ane 'chomp;$rep{$F[0]}=${$F[1]}; END{open(A,"file"); while(<A>){ s/\b$_\b/$rep{$_}/g for keys(%rep); ...


3

If you want more portable, you can use \< and \>: sed -i "s/\<$SEARCH\>/$REPLACE/g" file \< and \> work in gsed, ssed, sed15, sed16, sedmod. \b and \B work in gsed only. In Mac OSX, you must use this syntax: sed -i '' -e "/[[:<:]]$SEARCH[[:>:]]/$REPLACE/g" file


4

If you're using GNU sed (which bare -i suggests you are), there is a "word boundary" escape \b: sed -i "s/\b$SEARCH\b/$REPLACE/g" \b matches exactly on a word boundary: the character to one side is a "word" character, and the character to the other is not. It is a zero-width match, so you don't need to use capturing subgroups to keep the value with \1 and ...


2

The first issue here is that your values are quoted. I suggest you simply remove the quotes with a sed command and then, if you really need them, put them back after you've processed the file with awk. Something like sed "s/'//g" UiO-66Zr-EH.mof | awk '{$2=q $2 q}' q="'" The trick above sets the variable q to ' so q $2 q is equivalent to '$2'. Just an ...


2

Instead of doing a regex match on the second column, you probably just want to a string comparison. To do this with the example you have given, you have to include the single quotes in the comparison which turns the whole thing into a bit of a shell quoting nightmare. Doing that gives the following: awk "\$2==\"'Zr1'\" { \$3=\"2.222.d0\" } ...



Top 50 recent answers are included