filenames

How can I just extract one underbar-separated field from a filename?

北慕城南 提交于 2021-02-05 10:48:07
问题 I have a list of file names like this: REG_2016120200hourly_d01_20161202_00_00_00.nc Of this name I would like to extract and put in a variable: 1)date 20161202 for file in /path/*; do filename=$(basename -- "$file") date=${filename:4:8} echo $date done and this is working, the script give me 20161202 and I don't know why 2)timestep 00 I need to take the firsts two zero 00 and I'm trying with timestep=${filename:34:36} but this doesn't work. I'm a little bit surprised because I used the same

Obtaining file basename with a prespecified extension in Python

烈酒焚心 提交于 2021-02-05 06:35:28
问题 I have the following string: /path1/path2/foo.bar.qux.txt What I want to do is to extract the basename by specifying the extension. If I define the extension to be .bar.qux.txt then the base name is " foo ". Then if the extension is .qux.txt then the base is: foo.bar . Perl has the following function: use File::Basename; my $longones = "/path1/path2/foo.bar.qux.txt"; my $base = basename($longones,"*.bar.qux.txt"); print "$base\n"; What's the Python way to do it? 回答1: There's no built-in

Implementing getarg subroutine call

China☆狼群 提交于 2021-02-04 21:44:11
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Implementing getarg subroutine call

落爺英雄遲暮 提交于 2021-02-04 21:43:46
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Implementing getarg subroutine call

霸气de小男生 提交于 2021-02-04 21:42:43
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

FAT32: set long filename and 8.3 filename separately [closed]

空扰寡人 提交于 2021-02-04 21:35:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 8 years ago . Improve this question I need to construct a SDHC card (FAT32) with a directory where I have chosen the short and long filenames independently. E.g. short filename MYDIR but long name i am a cool name. yeah. check out the awesomeness. Based on Wikipedia, there is no mandatory correlation between the two names, so

How do I change case of the names of multiple files, already committed?

╄→尐↘猪︶ㄣ 提交于 2021-01-31 05:44:26
问题 I want to rename all 500 images which I had uploaded on Git to lowercase. Git ignores the casing if I push the code with lowercase images. Is there any specific command to fix it? OS: MAC 回答1: Git ignores the casing if I push the code with lowercase images ... This is not actually true. To understand the problem properly, you need to know the following things: Git doesn't store files , but rather commits . Commits do store files, but not in the same way your computer does normally. The files

Subset data in a large list based on filename of the dataframes in the list

余生长醉 提交于 2021-01-29 18:45:57
问题 I'm working with a large list that contains 450 dataframes. I'll make an example of the names of the dataframes : ALL_SM51_SE1_hourly, ALL_SM201_SE1_hourly, ALL_SM501_SE1_hourly ALL_SM51_SE2_hourly, ALL_SM201_SE2_hourly, ALL_SM501_SE2_hourly ................................................................... ALL_SM51_SE150_hourly, ALL_SM201_SE150_hourly, ALL_SM501_SE150_hourly The dataframes contain measured soil moisture data at different depths (5cm, 20cm, 50cm, represented by "SM51, SM201,

C#: How would you make a unique filename by adding a number?

霸气de小男生 提交于 2021-01-28 07:57:16
问题 I would like to create a method which takes either a filename as a string or a FileInfo and adds an incremented number to the filename if the file exists. But can't quite wrap my head around how to do this in a good way. For example, if I have this FileInfo var file = new FileInfo(@"C:\file.ext"); I would like the method to give me a new FileInfo with C:\file 1.ext if C:\file.ext existed, and C:\file 2.ext if C:\file 1.ext existed and so on. Something like this: public FileInfo MakeUnique

How to use wildcard in the middle on the string? bash

孤街浪徒 提交于 2021-01-28 01:26:33
问题 I am writing a bash script My files are like: file="${nodeID}_00000_19700101010${ts}_udp_filtered.pcap" . Is it possible to instead of 00000 use any 5digit number? I thought about using file="${nodeID}_ * _19700101010${ts}_udp_filtered.pcap" sometimes I have 00001, sometimes 00004, etc. 回答1: Something like echo "${nodeID}"_[0-9][0-9][0-9][0-9][0-9]_19700101010"${ts}"_udp_filtered.pcap Note, * and [something] won't expand in quotes, so only the variables are quoted above. 回答2: for match in $