質問編集履歴

1

修正

2023/07/19 09:17

投稿

SUSU0703
SUSU0703

スコア17

test CHANGED
File without changes
test CHANGED
@@ -9,6 +9,56 @@
9
9
  Hanako @{display_value=Hanako Tanaka; link=https://contoso.service-now.com/api/now/table/sys_user/b7bc02d2db48b4184f08b29a68ahgb22
10
10
 
11
11
  これで、最後の31文字部分だけを残して、 a7bc02d2db48b4184f08b29a689619ed その前の文字列を全て消して
12
- 違うCSVファイルに出力したいのですが、どのようにすればよいかご存じの方、ご教授頂けないでしょうか。
12
+ 違うCSVファイルに出力したいのですが、どのようにすればよいかご存じの方、ご教授頂けないでしょうか。色々試していますがうまくできません。
13
+
14
+ # Set the path to CSV file
15
+ $csvFilePath = "./test1.csv"
16
+
17
+ # Read the CSV file
18
+ $csvData = Import-Csv -Path $csvFilePath
19
+
20
+ # Define a regular expression pattern to match the desired format
21
+
22
+ $pattern = '@{display_value=.*\/(\w{31})}'
23
+
24
+ # Loop through each row in the CSV data
25
+
26
+ foreach ($row in $csvData) {
27
+
28
+ # Extract the last 31 digits using the regular expression pattern
29
+
30
+ if ($row.assigned_to -match $pattern) {
31
+
32
+ $lastThirtyOneDigits = $matches[1]
33
+
34
+ $row.assigned_to = $lastThirtyOne
35
+ }
36
+ }
37
+ $csvData | Export-Csv -Path ./test2.csv -NoTypeInformation
38
+
39
+ #------------------------------------------------------------------
40
+
41
+ # Set the path to CSV file
42
+ $csvFilePath = "./test1.csv"
43
+
44
+ # Read the CSV file
45
+ $csvData = Import-Csv -Path $csvFilePath
46
+
47
+ $pattern = '@{display_value=.*(\d{31})$'
48
+
49
+ # Loop through each row in the CSV data
50
+
51
+ foreach ($row in $csvData) {
52
+ # Extract the last 31 digits using the regular expression pattern
53
+
54
+ if ($row.URL -match $pattern) {
55
+
56
+ $lastThirtyOneDigits = $matches[31]
57
+
58
+ $row.URL = $lastThirtyOne
59
+ }
60
+ }
61
+
62
+ $csvData | Export-Csv -Path ./test2.csv -NoTypeInformation
13
63
 
14
64
  どうぞ宜しくお願い致します