how to get OS name in Windows Powershell using functions [closed] - function

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to return OS name using functions in Windows Powershell.
I built this code, but i don't get any results. Any help please?
Function Get-OSName
{
(Get-WmiObject Win32_OperatingSystem).Name
}
"Name of the OS: $(Get-OSName)"
Thank you.

Try exploring the object to find out what property you want:
Get-WmiObject Win32_OperatingSystem | select -Property *
You will notice the 'Caption' property contains the friendly OS name, as micky-balladelli mentioned. Your example would change to:
Function Get-OSName
{
(Get-WmiObject Win32_OperatingSystem).Caption
}
Cheers!

You have omitted a critical part of your screen, with your image. What is
important is the line directly after the last line shown. If the last line shown
is truly the last, then you still need to press Enter once more.
Consider this command
PS > 'hello world'
hello world
Notice the result printed as soon as I hit Enter. However certain
actions, like defining a function cause PowerShell to enter interactive mode.
Once PowerShell is in interactive mode it will require pressing Enter
twice to start the evaluation. Example
PS > function foo {
>> echo bar
>> }
>> 'hello world'
>> 'dog bird mouse'
>>
hello world
dog bird mouse
Notice this time around I was able to enter a command after the same
'hello world' command.

Related

Remove the comma in the first column in .csv file using bash code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I have a data as follows;
12432,20230
I want to remove the comma and replace it with space and want the output as follows;
12432 20230
I used the following code;
sed ’s/,/ /g’ file.csv > file.geno
but it gives error as;
sed: -e expression #1, char 1: unknown command: `�'
Your code is using "smart quotes", ’, instead of single quotes, ', just fix that and your syntax error will go away, i.e. instead of:
sed ’s/,/ /g’ file.csv > file.geno
use:
sed 's/,/ /g' file.csv > file.geno
You don't need the g at the end btw since you only have 1 comma in your input.

Run sequentially cir and net files with tcl/tk [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 1 year ago.
Improve this question
I would like to give me your advice about using cadence orcad
so I can run sequentially cir or net(netlist) files with pspice.exe in cmd of my pc.
I use tcl/tk language.I have tried a few things without any results.
I want to make something similar to this one:
set top {C:\Users\file1.net C:\Users\file2.net};
foreach a $top
{exec D:\\tools\\bin\\pspice.exe -r $a}
There are two problems in your code.
The first problem is that \f is an escape character sequence in lists (for “go down one line”, IIRC; point is you don't want that interpretation). The second problem is that you've got your brace placement wrong in your foreach.
The first problem is best addressed by using / instead of \, and then using file nativename on the value fed to the OS. (You have to do that manually for argument to executables in expr; Tcl can't fix that for you entirely automatically.) The second problem is just a syntax error.
Try this:
set top {C:/Users/file1.net C:/Users/file2.net}
set pspice D:/tools/bin/pspice.exe
foreach a $top {
# Tcl knows how to convert executable names for you; not the other args though
exec $pspice -r [file nativename $a]
}
On Windows you may also try:
package require twapi
set top {C:/Users/file1.net C:/Users/file2.net}
foreach a $top {
twapi::shell_execute -path [file nativename $a]
}
This will work only if *.net files are already associated with PSpice application.
The code above rely on TWAPI extension (if you have it) and its shell_execute function, to open a document just like double-click works.
It's always a good idea to avoid backslashes in your code (no need to put it twice to escape them), file nativename will do the job for you.
Source: https://twapi.magicsplat.com/v4.5/shell.html#shell_execute

Prettify a one-line JSON file [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I downloaded a 203775480 bytes (~200 MiB, exact size is important for a later error) JSON file which has all entries all on one line. Needless to say, my text editor (ViM) cannot efficiently navigate in it and I'm not able to understand anything from it. I'd like to prettify it. I tried to use cat file.json | jq '.', jq '.' file.json, cat file.json | python -m json.tool but none worked. The former two commands print nothing on stdout while the latter says Expecting object: line 1 column 203775480 (char 203775479).
I guess it's broken somewhere near the end, but of course I cannot understand where as I cannot even navigate it.
Have you got some other idea for prettifying it? (I've also tried gg=G in ViM: it did not work).
I found that the file was indeed broken: I accidentally noticed a ']' at the beginning of the file so I struggled to go to the end of the file and added a ']' at the end (it took me maybe 5 minutes).
Then I've rerun cat file.json | python -m json.tool and it worked like a charm.

How do I replace characters with a variable in CMD? [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 trying to make a batch file that asks questions then uses the variables to make a html file. Is there a way to replace characters WITHIN COMMAND LINE with the stored variables?
I am making my batch file have a very short HTML template with the basics (font-size, colour) and I want the user to be able to choose the font size and colour then have the batch file output the completed template as a HTML. Heres a bit of my bat file. How do I replace the %%% in a cmd environment?
<html><body>
Hello
</span>NAME HERE
<p <span style='font-size:%%%pt'>
<span style='color:%%%'>
</span></p></body></html>"
You have to escape all <> with a caret in a batch, otherwise this is trivial and should be no problem - even for beginners.
:: Q:\Test\2018\05\08\SO_50222677.cmd
#Echo off&SetLocal
Set /P "_FileName=FileName :"
Set /P "_Size=Size in pt:"
Set /P "_Color=html color:"
Set /p "_Name=Hello name:"
( Echo:^<html^>^<body^>
Echo:Hello
Echo:^</span^>%_NAME%
Echo:
Echo:^<p ^<span style='font-size:%_Size%pt'^>
Echo:
Echo:^<span style='color:%_Color%'^>
Echo:
Echo:^</span^>^</p^>^</body^>^</html^>"
) > "%_FileName%"

replace all whitespace in text file unless after # character [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'm trying to replace all whitespace in a text file with a \t so that I can load the contents into SQL. The problem that I'm having is that I only want to replace white space before the a string containing a mix of white space and other characters.
Before:
1.5e-61 5.3e-58 132 0.99 # 3 # 398 # -1 # ID=6412_1;partial=11;start_type=Edge;rbs_motif=None;rbs_spacer=None;gc_cont=0.394
After:
1.5e-61\t5.3e-58\t132\t0.99\t# 3 # 398 # -1 # ID=6412_1;partial=11;start_type=Edge;rbs_motif=None;rbs_spacer=None;gc_cont=0.394
I essentially want to keep everything after the # character as a string. Can anybody help please?
Parse, process, compose.
while (<>) {
chomp;
my ($data, $comment) = split(/(?=#)/, $_, 2);
$data =~ s/\s+/\\t/g;
print($data, $comment, "\n");
}