So the final part I'm missing in my assignment is a way to print ONLY the file names (rather than ./usr/etc/folder/directory/file.pdf, I want to print file.pdf) but I can't remember how to do this. What is the best/shortest way to accomplish this?
basename
Simple answer: use /usr/bin/basename
Since using C Shell the correct answer is use string modifier :t to get the filename.
Example set FILENAME = $PATH:t
Related
In webstorm 2017.1.1 I would like to find and replace a simple string with variable in the replace, for example:
find: testID:'
replace: testID:'${FILE_NAME}
And I expect the replace result will be testID:'MY_FILE_NAME...
Someone know if it's possible vie webstorm or via any plugin related?
Thanks in advance.
As #SupunWijerathne said, the IDEA replace dialogue is not aware of variables. However, this is something you could easily do in a shell. For example, on Linux, and with a replacement string without any special characters, you could do this:
sed -i "s/testID:'/testID:'${FILE_NAME}/g" my-file.txt
In pig script, I would like to find a way to escape the delimiter character in my data so that it doesn't get interpreted as extra columns. For example, if I'm using colon as a delimiter, and I have a column with value "foo:bar" I want that string interpreted as a single column without having the loader pick up the comma in the middle.
You can try http://pig.apache.org/docs/r0.12.0/func.html#regex-extract-all
A = LOAD 'somefile' AS (s:chararray);
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(s, '(.*) : (.*)'));
The regex might have to be adapted.
It seems Pig takes the Input as the string its not so intelligent to identify how what is data or what is not.
The pig Storage works on the Strong Tokenizer. So if u want to do something like
a = LOAD '/abc/def/file.txt' USING PigStorage(':');
It doesn't seems to be solving your problem. But if we can write our own PigStorage() Method possibly we could come across some solution.
I will try posting the Code to resolve this.
you can use STRSPLIT(string, regex, limit); for the column split based on the delimiter.
How would I write regex in Visual Studio's Find and Replace to change all instances of the following text:
If (whatever control and overloads) = "" then
To this:
String.IfNullorEmpty(whatever control and overloads) then
Search for:
If (.*) \= "" Then
And Replace with:
String.IfNullOrEmpty($1) Then
Although, what I think you actually meant was:
If String.IsNullOrEmpty($1) Then
The trick is in simply surrounding the desired part of the pattern in parenthesis to make it a RegEx group. Then in the replace string you can reference the groups with the $ syntax.
I want to execute a shell command (I want to touch a file). I use system("shell command") to execute the command.
For example I want to touch the file at path /Users/username/New Folder/. Now I need to convert the NSString in a format that is conform to shell commands like /Users/username/New\ Folder.
Is there any method that does a conversion like this?
NOTE: It is NOT just replacing a whitespace with \. If you have a special character in the path like /Users/username/Folder(foo)/ the "shell path" looks like this /Users/username/Folder\(foo\)/
There is no need to convert the path, you can surround it in single quotes. Just use:
touch 'path'
You can enclose the parameters that contain spaces with " " marks.
touch "/Users/username/New Folder/"
At least this works at the shell prompt
Don't use system. It's insecure and unpredictable. Surrounding the string with quotes is not sufficient.
Use the execve style functions instead. They are simple and secure.
Okay so what I'm trying to do is get the filename from OpenFileDialog/SaveFileDialog, only without the full path, and dump said filename into a variable so I can use it for other things.
Using the Split function, I can get any part of the array between the delimiters ("\"), but what I'm trying to do is get all the information after the LAST delimiter in the string.
You could use Path.GetFileName to get the file name.
Why not convert this to a Fileinfo object and pull the name property?
(MSDN Link)