Tag Info

New answers tagged

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

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"


1

With GNU sed anhd grep, you can try: sed -n "/$(date +%y%m%d)/,\$p" file | grep -c partitioned /pattern/,$ matched first pattern to the end of file. With your input: $ sed -n "/$(date +%y%m%d)/,\$p" 1.txt | grep -c partitioned 1 Without matching date: $ sed -n "/$(date +%y%m%d)/,\$p" 1.txt | grep -c partitioned 0


1

You could try chaining two greps together: grep `date +"%y%m%d"` mysql-error.log | grep -c partitioned Or even simpler: grep -c "`date +%y%m%d`.*partitioned" mysql-error.log EDIT As the date and the word 'partitioned' are on different lines, then: d=$(date +"%y%m%d"); awk '/'$d'/,EOF {print $0}' mysql-error.log | grep -c partitioned Or: awk ...


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\" } ...


2

With GNU grep and xargs: grep -rlZ search-text some/dir/ | xargs -r0 cat > dump.test -l is to list the files that contain at least one line matching the search-text. -Z is to print that line NUL-delimited so it can be safely passed to xargs -0. -r to search in all the files inside some/dir/ recursively. POSIXly: find some/dir -type f -size +0 -exec ...



Top 50 recent answers are included