New answers tagged

0

I was skeptical of Stéphane’s answer, however it is possible to abuse $#: $ set `seq 101` $ IFS=0 $ [ $# = 0 ] bash: [: too many arguments This is a contrived example, but the potential does exist.


1

So it seems like there are extra quotes being inserted around the contents of noquotes.txt, but not around quotes.txt. This is just Bash being helpful. You'll notice it will put quotes around things whenever there's a symbol that would otherwise be interpreted by Bash. It acts just like you would, using quotes only when necessary. Try to put any of the ...


29

There are two problems with your example. The primary one is that you're assuming that regular expressions work the same as glob patterns in that * is a wildcard meaning "any sequence of characters." In regular expressions, * means "any number of the previous atom" instead, so fil* means f followed by i followed by zero or more l characters. You need to say ...


1

The line in your code weka $1 ${search["$1"]} is being subject to shell spliting. If you have not changed the variable $IFS that splitting will happen on spacetabnew line. The line gets expanded to: weka $1 ${search["$1"]} weka a -search "a params" -search "other a params" But getting split as described above, this is what it means: <weka> ...


1

The shell does not handle quoted quotes the way that you want. (Once the quotes are quoted, they are treated like regular characters.) You can trick bash into doing what you want. To start define an associative array: declare -A s s=( ["a"]='-search;a params;-search;other a params;' ["b"]='-search;just these params' ) As you can see, the string has the ...


1

Change ligne=`cat /var/log/svlog | grep "\$day"` to ligne=$(grep "$day" /var/log/svlog) To feed the contents of $ligne to awk, use echo "$ligne" | awk ...


2

Your attempts aren't working because you're trying to use shell operators such as && and > in the command executed by find, but you're typing those operators directly in the command, so they're executed by the shell that's calling find. Your commands are parsed as find … > tmp.$$ && mv … e.g. the first find invocation is find ./ ...


5

You probably have the nullglob shell option enabled; this causes any word containing a globbing character (* or ?) to be removed if the glob doesn't match anything. Thus, if you're in a folder which doesn't contain any file, folder etc. with a single-character name, ? won't expand to anything and will instead be removed; likewise, not-a-command? is unlikely ...


2

it's like *, but it represents a single character e.g. show the three-character root directories: $ ls -d /??? /bin /dev /etc /lib /mnt /opt /run /sys /tmp /usr /var note that /home is not shown because it doesn't match Use [?] or \? or wrap your strings in quotation marks ("foo?" or 'bar?')


0

There are two problems. The first is that the shell doesn't expand $j inside single quotes: '$j' tells the shell that you want the string $j, not the value of the variable j. In this case, because the value only contains digits, you could put it outside of single quotes: awk '/time: '"$j"'/{for(i=1;i<=100;i++}{getline;print}}' file > fileX-"$j".txt ...


1

Why does the grep command ignore the period in the search string? It doesn't. To prove, run grep . file which is an easy way to remove all empty lines from file. In other words, . is the regex atom for any single character (except newline). To literally match a dot, the atom must be escaped as \.


4

You could use fgrep find . -type f -name "*.sql" -exec fgrep -i -l 'schema_name.' {} + which on older Unix operating systems may very well be a lot faster (fgrep, grep and egrep used to be 3 different executables, and there fgrep was a lot faster because it omitted everything related to regex entirely - on eg GNU based systems these three programs are ...


0

You have to pass the $j shell variable to awk: awk -v jj="$j" '...' Note that this assumes that the value of the variable does not contain backslashes, as the argument to awk -v undergoes backslash expansion.


12

That's grep issue, not find. grep matches pattern using regular expression by default, the pattern schema_name. means any character follows the string schema_name. If you want to match the dot . literally, you have to escape it with a backslash \: find . -type f -name "*.sql" -exec grep -il 'schema_name\.' {} + or using -F option: find . -type f -name ...


2

Escape the dot in the grep search pattern: find . -type f -name "*.sql" -exec grep -i -l 'schema_name\.' {} +



Top 50 recent answers are included