我正在尝试使用grep过滤文件名。我将这些文件名作为输入:
1234.txt
1234.txt.dev1
123.doc1
123.txt.dev1
123.txt.dev2
234.jpg
456.php
tmp
tmppppp
我想只列出文件名中有一个.
(点/周期)的文件。文件名和扩展名会有所不同,但不是固定的。
预期结果:
1234.txt
123.doc1
234.jpg
456.php
我可以用grep吗?
答案 0 :(得分:2)
将grep与per'ls正则表达式开关一起使用:
grep -P '^[^.]+(?<!\.)[^.]+\.[^.]+$' file
或简单地(归功于@gniourf_gniourf):
grep -E '^[^.]+\.[^.]+$' file
使用awk的另一种方式:
awk '{split($0, a, ".")} length(a) == 2' file
或
awk '!/^\./ && !/\.$/{split($0, a, ".")} length(a) == 2' file
如果您要跳过以.
1234.txt
123.doc1
234.jpg
456.php
答案 1 :(得分:-3)
只使用a过滤文件名。你可以使用:
theta = np.random.standard_normal((64, 4))
xs = np.zeros((available_states))
xs[some_index] = 1
def pi(xs, theta):
H_s_a_Theta = np.matmul(tf.transpose(theta), xs)
softmax = [scipy.exp(x) for x in H_s_a_Theta]
sum = np.sum(softmax)
return softmax / sum
first_derv_fn = tfe.gradients_function(pi, params = 'theta') #xs:0, theta:1
secon_derv_fn = tfe.gradients_function(first_derv_fn, params = 'theta')
或
cat file.txt | grep '\.'
或
grep '\.' file.txt