Tagged Questions
13
votes
3answers
434 views
What is the difference between [[ $a == z* ]] and [ $a == z* ]?
Is there is any difference between these two.
[[ $a == z* ]]
and
[ $a == z* ]
Can I have an example where they would have different outputs?
Furthermore, how does the working of [[ ]] differs ...
11
votes
4answers
437 views
How do I choose specific files in a different directory using bash?
I want to list (or delete, or do some other operation) on certain files in a directory, like this:
$ ls /opt/somedir/
aa bb cc aa.txt bb.txt cc.txt
$ ls /opt/somedir/(aa|bb|cc) ## pseudo-bash ...
7
votes
4answers
12k views
How do I grep for multiple patterns?
I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing
grep (foo|bar) *.txt
but the shell interprets the | as a pipe and ...
7
votes
2answers
697 views
How does a shell (bash, for example) expand regular expressions?
Assume that a directory has 100 files starting with the letter 'a'.
If I do a grep <some string> a* from the terminal, how will the shell handle this?
Will it expand the regular expression, ...
5
votes
3answers
178 views
difference between .* and * in regular Expression
I've a file named "test" that contains
linux
Unixlinux
Linuxunix
it's linux
l...x
now when i use grep '\<l.*x\>' , it matches :
linux
it's linux
l...x
but when i use grep '\<l*x\>' ...
4
votes
2answers
463 views
substrings and regexps
I have a string contained in a variable, and I want to extract substrings based on position relative to another substring. My solution seems to work unless the string is sent to a function as an arg. ...
4
votes
1answer
719 views
Print specific Exif image data values with exiv2
How do I print the image Exif date with a tool like exiv2?
My goal is to write the image year and month into separate variables. Do I really have to parse the output with regex or is there a ...
3
votes
3answers
396 views
Extracting text from a text file in bash
I have a large text file that is all one line. In the text are several sections that looks like foo=12345 and I need to extract them all as separate lines, ignoring the rest of the file.
For ...
3
votes
4answers
1k views
Applying a regex to stdin
In programing we often see the use of Regular Expressions.
One of the most common forms is:
newText = text.replace( /regex/, 'replacementString' )
If stdin is text and stdout is newText, what ...
3
votes
2answers
819 views
What regular expression engine type does bash use?
I use RegEx Buddy to prototype and debug my regular expressions. RegEx Buddy allows me to choose between a number of different regular expression engine types (.NET, Java, Perl, GNU BRE, GNU ERE, ...
3
votes
2answers
365 views
ANDed conditional using regexp and variables
I want to test whether a line, read in from a file, has a specific beginning AND an ending containing a word held in a variable. Here's some code:
The input file is:
line one
#; line two
#; line ...
3
votes
2answers
64 views
find command with regex {1,2}
I have been trying to create a find command string that will find all files that end with a number 1-99 but exclude all others.
e.g. I want to find myfile1 myfile99 but not myfile456 and not ...
2
votes
1answer
2k views
Using regex inside if clause in bash
Look at this if block:
#!/bin/bash
str="m.m"
if [[ "${str}" =~ "m\.m" ]]; then
echo "matched"
else
echo "not matched"
exit 1
fi
exit 0
This should print "matched", but it doesn't. ...
2
votes
3answers
554 views
How to cut the output to only gather the filename and get-parameter?
I have multiple files with multiple links that are formatted like this:
<a href="http://example.com/fnord.layername.html?parameter=FOO-_-BAR-_-FNORD" class="poit">
<img ... />
...
2
votes
1answer
155 views
Why doesnt ctrl+d work with this?
I wanted a simple way to process text in my clipboard without having to create a file. I tried using the following line:
awk '{print $1}' <(cat)
but I couldn't send cat the EOF character using ...