How to set a text content of a specific column as a variable using Batch or PowerShell? [closed] - powershell

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 months ago.
Improve this question
For example, I have a file/file output with the following content:
2022-10-16 14:33 1,860,477 Mausi-~1.JPG Mausi-wife.JPG
There are spaces between these five blocks in between, i.e. between date and time and number and file name and another file name.
I would now like to set only the fourth column of this as a variable. Is this possible?

Split the string on spaces, update the desired value in the resulting array, and then stitch back together with -join:
$row = '2022-10-16 14:33 1,860,477 Mausi-~1.JPG Mausi-wife.JPG'
# split into individual field values
$fields = $row.Split(' ')
# update/overwrite the 4th item in the resulting string array
$fields[3] = "New value"
# stitch row back together with `-join`
$row = $fields -join ' '

Related

Perl script to remove new line character and move next line data to previous line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I have input like below
"ID"|"Desc"
"100"|"
The data present in Desc column has new line characters.
So the data came to second line.
Some records of data went to third line. But I need all data to be present in first line."
"101"|"This record desc is correct data which has present in single line. So I need data to present in single line."
I need output like below,
"ID"|"Desc"
"100"|"The data present in Desc column has new line characters.So the data came to second line.Some records of data went to third line. But I need all data to be present in first line."
"101"|"This record desc is correct data which has present in single line. So I need data to present in single line."
Can someone please help the Perl script where we can achieve above requirement.
Use Text::CSV_XS to process the file as it can parse it correctly.
perl -MText::CSV_XS=csv -wE 'csv( in => shift,
always_quote => 1,
sep_char => "|",
eol => "\n",
on_in => sub { $_[1][1] =~ s/\n//g } );
' -- file.csv > newfile.csv
I'm testing this in a Linux shell, you might need a different eol if you're in MSWin. Also, I don't know what rules Powershell uses for quoting, co you might need to use a different type of quotes.

how to print substring between quotes in a string in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
such string:
interface Loopback0 description "Loopback Interface for network management" ip address 10.20.30.40 255.255.255.255 no ip proxy-arp
how to print what is between " "?
Loopback Interface for network management
Assuming that the " character occurs only 2 times or if you want the first pair:
# Get the indices of the " characters
ind1 = exampleStr.find('"')
ind2 = exampleStr.find('"', ind1+1)
# Get the substring between the two indices
result = exampleStr[ind1+1:ind2]

How to extract only version number from a string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am extracting oracle version from windows using powershell command and i get result as 10.2.0.3.0Patch2, however i need to extract only numeric value i.e. 10.2.0.3.0 (only version number). Any way we can do it ?
Version info extracted is =
10.2.0.3.0 Production, 10.2.0.3.0Patch2 Production, 10.2.0.5.0 Production, 11.2.0.4.0 Production
You can use a regular expression to extract a substring. Example:
"10.2.0.3.0Patch2" | Select-String '((?:\d{1,3}\.){4}\d{1,3})' | ForEach-Object {
$_.Matches[0].Groups[1].Value
}
# Outputs the string '10.2.0.3.0'
You can read more about regular expressions by reading the about_Regular_Expressions help topic:
PS C:\> help about_Regular_Expressions

Print a substring of an array value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have an array in the third element dataArr[2], I know it contains a 10 digit phone. I need to only read or print the first 6 digits. For instance if my phone is 8329001111, I need to print out the 832900. I tried to see if I can use substr but I keep reading or printing the full list. Do I need to dereference..
Try this :
$dataArr[2] =~ s/\s//g; # ensure there's no spaces
print substr($dataArr[2], 0, 6);
# ^ ^ ^
# variable | |
# offset start|
# |
# substring length

Converting single line to multiple lines in perl [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have file as below.
ID || DATE || AMOUNT
XX||20130801##20130901##20131001##20131101||100##200##300##400
and I want the output as below using perl.
xx||20130801||100
xx||20130901||200
xx||20131001||300
xx||20131101||400
Please help me how to convert using perl.
perl -F'\|\||##' -lanE'$.>1 or $" ="||",next; say "#F[0,$_,$_+4]" for 1..4' file
perl -F'\|\|' -lane '#a=split(/##/,$F[1]); #b=split(/##/,$F[2]); print "$F[0]||$a[$_]||$b[$_]" foreach 0..$#a;' file
Output:
ID || DATE || AMOUNT
XX||20130801||100
XX||20130901||200
XX||20131001||300
XX||20131101||400