I have a folder data that contains a list of images named as follow :
AHTD3A0001_Para1.tif
AHTD3A0002_Para1.tif
AHTD3A0003_Para1.tif
.
.
AHTD3A1012_Para1
I want to delete the first part of image name ( AHTD3A) in order to replace image names such as :
0001_Para1.tif
0002_Para1.tif
0003_Para1.tif
.
.
AHTD3A1012_Para1
please any suggestion for matlab code and thanks in advance
You can simply use strrep to replace part of a string.
oldnames = {'AHTD3A0001_Para1.tif' 'AHTD3A0002_Para1.tif'};
newnames = strrep(oldnames, 'AHTD3A', '');
% '0001_Para1.tif' '0002_Para1.tif'
If the filename prefix isn't always the same and you simply want four digits followed by _Para1.tif. You could instead use regular expressions with regexprep.
newnames = regexprep(oldnames, '.*(?=\d{4}_Para1\.tif)', '');
Or you can match it using regexp instead
newnames = regexp(oldnames, '\d{4}_.*', 'match', 'once')
Related
everyone. So, what I basically want to do is to search for all files that start with "dm" or end with ".tmp" in storage_path("app/public/session").
I already tried File::allFiles() and File::files() but what I get is all files that are into that session folder and I can't figure out how to do it. What I could find in here is questions on how to empty a folder but that's not what I am looking for. Thanks.
Try this code :
$files = File::allFiles(storage_path("app/public/session"));
$files = array_filter($files, function ($file) {
return (strpos($file->getFilename(), 'dm') === 0) || (substr($file->getFilename(), -4) === '.tmp');
});
Or you can use the glob function like this :
$files = array_merge(
glob(storage_path("app/public/session/dm*")),
glob(storage_path("app/public/session/*.tmp"))
);
In Laravel, you can use the File facade's glob() method to search for files that match a certain pattern. The glob() function searches for all the pathnames matching a specified pattern according to the rules used by the libc glob() function, which is similar to the rules used by common shells.
You can use the glob() method to search for files that start with "dm" or end with ".tmp" in the "app/public/session" directory like this:
use Illuminate\Support\Facades\File;
$storagePath = storage_path("app/public/session");
// Find files that start with "dm"
$files = File::glob("$storagePath/dm*");
// Find files that end with ".tmp"
$files = File::glob("$storagePath/*.tmp");
You can also use the ? and [] wildcard characters,
for example ? matches one any single character and [] matches one character out of the set of characters between the square brackets,
to search for files that match more specific patterns, like this:
// Find files that starts with "dm" and ends with ".tmp"
$files = File::glob("$storagePath/dm*.tmp");
Note that, File::glob() method return array of matched path, you can loop and see the files or use it according to your needs.
I am trying to replace text after "/" on foxpro. Shelly Jones/Foundation Director, How to delete everything after the "/"?
A common way of doing it is to combine the left() and atc() functions, like so:
lcStr = "Shelly Jones/Foundation Director"
lcNewStr = LEFT(lcStr, ATC('/', lcStr) - 1)
The -1 is needed to get the portion of the string ending before the / character.
Assuming this is VFP 7 or later, use the StrExtract function:
cResult = STREXTRACT(cOriginalString, '', '/')
My input file name is words.txt as below . Also there is no space in each record of this below file .
Hi
Hi
How
I am loading this file into Pig
words = LOAD '/user/inputs/words.txt' USING PigStorage() AS (line:chararray);
words_each = FOREACH words GENERATE REPLACE(line,'','|') ;
dump words_each;
I am getting output as
|H|i|
|H|i|
|H|o|w|
But I would like to know how exactly REPLACE functions treats '' which is my second argument in REPLACE function .
There is no empty space in my file, then how come I am getting | in my output .
Well, As per your statement, REPLACE function is called on ''. It doesn't contain any whitespace.
If you want to replace the space, you need to give it like this ' '. +
Both are different conditions as given below:
words_each = FOREACH words GENERATE REPLACE(line,'','|') ; // without space
words_each = FOREACH words GENERATE REPLACE(line,' ','|') ; // with space
First condition will add the Pipe symbol(|) after each character, while 2nd condition won't make any impact because there is no space in your file content.
I need to read a text file like this,
regular: 12/04/2013, 13/04/2013
extract 'regular', and save it in a variable and all the dates in an array. How can I do this?
Based on what you say you tried, would the following do what you want?
data = line.split(/: */) # => ["regular", "12/04/2013, 13/04/2013"]
#customer = data[0] # => "regular"
#dates_array = data[1].split(/, */) # => ["12/04/2013", "13/04/2013"]
I used * to match (and eliminate) multiple blanks. I'm assuming here that you don't want the blanks, comma, or the colon (:) separator included in your results. If that's not correct, adjust the regular expressions accordingly.
I have the following output:
time = 15:40:32.81
And I want to eliminate : and the . so that it looks like this:
15403281
I tried doing a
time.gsub(/\:\s/,'')
but that didn't work.
"15:40:32.81".gsub(/:|\./, "")
time = '15:40:32.81'
numeric_time = time.gsub(/[^0-9]+/, '')
# numeric_time will be 15403281
[^0-9] specifies a character class containing any character which is not a digit (^ at the beginning of a class negates it), which will then be replaced by an empty string (or, in other words, removed).
(Updated to replace \d with 0-9 for clarity, though they are equivalent).
If you want to be fancy and use an actual time object...
time = Time.now
time.strftime("%H%M%S") + time.usec.to_s[0,2]
# returns "15151788"
time.delete ':.'
But it'll edit your variable. If you don't want it:
time.dup.delete ':.'