Makefile split name by token - linux

I need to get a token from the name of current directory, but I want to split it by name.. so say if I have
/home/test/one_two_three
or
/home/test/two
at both cases I'd like to get the 'two' only, i.e. chop everything before after and including '_'
so far I have
result=$(notdir ${PWD})
but how do I then split it?
Thx!

Related

How to create different projects within a group in Gitlab

I would like to create a list of projects within a "group" using the terminal in my machine. The group is private and I'm assuming I need a personal access token to reach it.
I saw in Gitlab API I should use POST command for this: https://docs.gitlab.com/ee/api/projects.html#create-project. But I don't see how to specify the group I want to create it into. Using this question: How do you create a project in a specific group via GitLab API?, I could write the command:
curl --header "PRIVATE-TOKEN: my-personal-access token" -X POST "https://gitlab.com/api/v4/projects?name=mylaboratory%2Fgroupname%2Fproject name"
After that I'm getting:
{"message":{"name":["can contain only letters, digits, emojis, '_', '.', dash, space. It must start with letter, digit, emoji or '_'."],"path":["can contain only letters, digits, '_', '-' and '.'. Cannot start with '-', end in '.git' or end in '.atom'"]}}
Here is my example url:
https://gitlab.eth.ch/api/v4/projects?path=lasec%2Fstudent-repos-cs372-2021%2Fgroup31
Is there a way to specify these new projects should disable rewriting commit history?
Try 1
Fixed changing .com to the relevant extension.
Try 2
From another computer the error curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) goes away, this may be related to the connection as pointed in the comments.
Try 3
The attribute you're looking for in the API is the namespace_id, and should be the ID of the group that you'd like to create the project within. If you wanted to create a nested group structure, each group you create can accept a parent_id which should be the ID of its parent.

Amazon S3 - How to recursively rename files?

I'm trying to fetch my files via the s3.getObject() method in my node.js backend.
Trouble is, upon uploading the files to my bucket, I failed to replace special characters, dashes, and white-spaces. So, any files that have a Key value of (e.g., a Key with the value of 10th Anniversary Party (Part 1) 1-23-04 has an endpoint of 10th+Anniversary+Party+(Part+1)+1-23-04).
This becomes troublesome when trying to encode the URI for fetching. I'd like to replace all dashes, white-space, and special chars with a simple underscore. I've seen some possible conventions using the aws-cli, however I am unsure what the best command for this is. Any advice would be greatly appreciated.
You could write a program that:
Lists the contents of the bucket
Calls CopyObject() to copy the object to a new Key
Calls DeleteObject() to delete the previous copy
Or, you could take advantage of the fact that the AWS CLI offers a aws s3 mv command that will Copy + Delete for you.
I often simply create an Excel spreadsheet with the existing names, and a formula for determining what name I'd like. Then, I create a third column with:
aws s3 mv [Column 1] [Column 2]
Use Copy Down on the rows to get all the mv commands. Then, copy the column of commands, paste them into the command-line and it will rename all the objects in Amazon S3! (Test with 1-2 lines first, in case there is an error in the formula.)
This might seem primitive, but it's a very quick way to make the changes.

Get a Steam key from a txt file then move it to another

I'm currently working on a Steam bot project that trades Steam items for Game keys. I'm already done with all the trading part, and the only part missing now is the part where the script actually looks for a key in my txt file. (one key per line)
I have a variable ready called totalKeyWeGive that outputs 1 , 2 , 3 etc depending on how many keys is the user buying.
So now I want to 1. get 1 , 2 , 3 etc keys from my file, then move these used keys to another file.
How can I do that ?
this is the part that I need to modify (everything is working) :
offer.accept(offer);
console.log("OFFER ACCEPTED");
//loop on how much we give the key
//get steamkey from file here ------
}
var textMsg = "Hello ! You bought "+totalKeyWeGive+ " Game keys. Your keys are: "
}
client.chatMessage(offer.partner.getSteamID64(), textMsg);
Thanks to everyone who will take the time to read this post. It's kinda messy, sorry about that :/
Not sure how the keys are organized in the txt file, but assuming they are one per line you could do something like this: https://stackoverflow.com/a/38843461/4686055
That is, before removing the line, save it in memory and write it to the target file.
Send an interval to slice() to remove multiple lines. Check this out for an example of how it works: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Hope this helps!
Update: an alternative approach could be to use the readlines module instead of reading the entire file into memory: https://nodejs.org/api/readline.html#readline_example_read_file_stream_line_by_line

file transfer Extra attachmate appends username to host file name

Hi when I try to download a file from mainframe, using attachmate extra it appends the username also along with it. I dont know where to turn it off.
like for example - file name is yyyy.file.name, then when i try to transfer of file it transfers username.yyyy.file.name.
in 3.4 the option to append user name is turned off. Still its happening
Enclose the entire dataset name (including the high-level qualifier) in single quotes. This is a TSO (not JCL) convention - if you refer to a dataset without single quotes, it pre-pends your user ID as the high-level qualifier; however if you place single quotes around the dataset name it will take it 'as is' (well, it will uppercase it, since all z/OS dataset names are uppercase, but otherwise it will be 'as is').

How to edit multiple file names at once?

I have directory full of .txt files (2000 files). they have very long name. I want to edit their name and just keep certain letter from inside of their name as file name.
like this :
UNCID_279113.TCGA-A6-2683-01A-01R-0821-07.100902_UNC7-RDR3001641_00025_FC_62EPOAAXX.1.trimmed.annotated.gene.quantification.txt
I want eliminate this long names and just keep the name starting from TCGA and ending after three - ; for example, my new file name would be : TCGA-A6-2683-01A
does anybody knows how can I do this for whole files in one directory?
Assuming the files are in the current directory:
library(gsubfn)
pat <- "TCGA-[^-]*-[^-]*-[^-]*"
file.names <- dir(pattern = pat)
new.names <- strapplyc(file.names, pat, simplify = TRUE)
file.rename(file.names, new.names)
Create a shell/batch script Here is a variation. It produces a UNIX shell file or a Windows batch file. You can then review the file and run it:
# UNIX
writeLines(paste("mv", file.names, new.names), con = "tcga_rename.sh")
shell("tcga_rename.sh")
or on Windows:
# Windows
writeLines(paste("rename", file.names, new.names), con = "tcga_rename.bat")
shell("tcga_rename.bat")
REVISED: Factored out pat, simplified and added variations.
Assuming your files are in the current working directory, try
library(stringr)
files <- list.files(".", pattern=".txt")
file.rename(files, str_extract(files, "TCGA(-\\w+){3}"))
You can do something like this:
pattern <- ".*(TCGA-[^-]+-[^-]+-[^-]*).*"
file.rename(
list.files("."),
sub(pattern, "\\1", list.files("."))
)
But be super careful that the sub command does what you think it will do before you run the full thing (i.e. just run the sub piece). Hard to be sure this won't cause a problem without knowing what patterns you have in your file names.
Also, in this case replace list.files(".") with your directory. Note you don't need to filter our the files that match the pattern in the first place since sub will only modify the file names that do match the pattern (not super efficient if you have a lot of files that don't match the pattern, but easier to write, if a concern, you can use the pattern argument as Greg Snow does).
You cane use list.files() to get a list of the filenames in the directory, then use substitute with regular expressions to edit the names, then file.rename to actually do the renaming.
Something like (untested):
curfiles <- list.files(pattern='TCGA') # only grab files with TCGA in them
newfiles <- sub("^.*(TCGA-[a-zA-z0-9]+-[a-zA-Z0-9]+-[a-zA-Z0-9]+).*$", "\\1", curfiles)
file.rename(curfiles,newfiles)

Resources