[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to blend these txt lines in a random way?

Posted on 2016-10-18
8
Medium Priority
?
61 Views
Last Modified: 2016-10-18
how to blend these txt lines in a random way?for example i have this:

john
john1
john123
miami
miami3
miami@1
london123
london

How to blend those lines to look, something like this:

john
miami
john1
london
john123
miami@1
london123
0
Comment
Question by:john lambert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 13

Expert Comment

by:Dustin Saunders
ID: 41848765
Sort by random.

Example:

$list = "john","john1","john123","miami","miami3","miami@1"
$list = $list | Sort-Object {Get-Random}


foreach ($item in $list)
{
    Write-Host $item
}

Open in new window

1
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41848786
Nice @Dustin, and way better / shorter than anything hacked together in a DOS BAT approach.

I'm also not aware of any Windows non scripting tools (like SORT.EXE) that have any capability to randomize the output when "sorting".

~bp
0
 

Author Comment

by:john lambert
ID: 41848819
for WINDOWS OS please..and for BIGFILE.TXT
thank you
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 13

Expert Comment

by:Dustin Saunders
ID: 41848837
You can use Get-Content and the path to the file to get the list from text.

$list = Get-Content "C:\test\list.txt"
$list = $list | Sort-Object {Get-Random}


foreach ($item in $list)
{
    Write-Host $item
}

Open in new window


If you want to randomize and write the changes back to your text file, use:
$list = Get-Content "C:\test\list.txt"
$list = $list | Sort-Object {Get-Random}
Set-Content "C:\test\list.txt" $list

Open in new window

Or if you want to write to another file, just change the path after 'Set-Content'
1
 
LVL 57

Expert Comment

by:Bill Prew
ID: 41848846
And just to clarify, this is a WINDOWS OS solution using Powershell.  You can save the script shown above as a .ps1 file, and then run it from a command line or a batch file by doing:

powershell.exe -ExecutionPolicy Bypass -File EE28977195.ps1

Open in new window

~bp
2
 

Author Comment

by:john lambert
ID: 41848853
working perfect but can u add please OUTPUT.TXT ??
0
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 2000 total points
ID: 41848854
Just change the save path on Set-Content and you're good to go.
$list = Get-Content "C:\test\list.txt"
$list = $list | Sort-Object {Get-Random}
Set-Content "C:\test\OUTPUT.txt" $list

Open in new window

1
 

Author Closing Comment

by:john lambert
ID: 41848861
great, thank you...
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question