I have a list of items like:
ERR001268_chr6
ERR001312_chr6
ERR001332_chr6
ERR001361_chr6
ERR001369_chr6
ERR001413_chr6
ERR001433_chr6
ERR001462_chr6
ERR001698_chr6
ERR001734_chr6
ERR001763_chr6
ERR001774_chr6
ERR001799_chr6
say now I want to concatenate ERR001268_chr6 until ERR001763_chr6.
I can do cat ERR001268_chr6 ERR001269_chr6....ERR001763_chr6 > xxx
But obviously I don't want to type in these items one by one...So any simple bash commands to do this?
thx
Assuming that the item list is the full list of 'files' under current directory:
cat `ls -1 ERR*_chr6 | head -n11` > xxx
Related
I'm trying to sort servers by the 2nd index of the name.
The server names are taken from file paths where they are the BaseName of the file.
I know that Select-Object has the parameter -Index, but I don't think that will work.
I am assuming that the best approach is with a PowerShell RegEx like "(?:^a-z))". This returns an unsorted list and I'm still googling around for a pattern that will sort by the 2nd Index.
Example of the Intended Output
Group the servers by name CC or DD
Server
------
ABCCWS01
CDCCWS01
ABDDWS01
CDDDWS01
Current Output
Sorts alphabetically by -Property name
$servers = Get-Item -Path
C:\ABDDWS01.ServerData,
C:\ABCCWS01.ServerData,
C:\CDCCWS01.ServerData,
C:\CDDDWS01.ServerData | Group BaseName -AsHashtable
foreach($computer in $servers.GetEnumerator() | Sort-Object -Property name)
{ ...DoSomething... }
Server
------
ABCCWS01
ABDDWS01
CDCCWS01
CDDDWS01
Then I tried to implement a PowerShell RegEx. But I'm stuck on how to properly use this to sort by the 2nd index. This example has no affect and returns the list unsorted. I've tried subbing in different patterns at the end "(?:^a-z))". So far my attempts either return the list unsorted or just a segment of the list.
I've googled around and tried many different things. If someone else wants to help puzzle this out, it is much appreciated.
Sort-Object -Property #{Expression={[RegEx]::Match($_.basename, "(?:^a-z))")}}
Sort-Object works by "ranking" each input according to the resulting value of calculating one or more property expressions against each input item - in your existing example, based on the the value of the name property.
As you've already found, property expressions doesn't have to be the value of any existing property though - they can be made up of anything - just pass a script block in place of the property name:
... |Sort-Object -Property {$_.name[1]}
The reason it doesn't work in your example is that the expression [RegEx]::Match($_.basename, "(?:^a-z))") returns a [System.Text.RegularExpressions.Match] object - and those can't be meaningfully compared to one another.
If you change the expression to resolve to a string instead (the matched value for example), it'll work:
... |Sort-Object -Property #{Expression={[RegEx]::Match($_.basename, "(?:^a-z))").Value}}
# or
... |Sort-Object -Property {[RegEx]::Match($_.basename, "(?:^a-z))").Value}
lets say I got this file:
https://www.wireless.miau.com/business/index.jsp?_requestid=839
https://www.wireless.miau.com/business/index.jsp?_requestid=859
https://www.wireless.miau.com/business/index.jsp?_requestid=886
https://www.wireless.miau.com/business/index.jsp?_requestid=897
https://www.wireless.miau.com/business/index.jsp?source=EENT042114500148N&_requestid=26&wtSlotClick=1-006Y3D-1-4&rel=nofollow
https://www.wireless.miau.com/business/index.jsp?token=46e134202bdd498c3369812e93c040122ecaf6b3
https://www.wireless.miau.com/business/index.jsp?token=Ae18464df3d728b2aa98286e843cd38cfa82c49d1&B2B_GTM=
https://www.wireless.miau.com/business/optin/optInEmailPopup.jsp?displayMode=1&from=businessCenter&bref=IBD903j370921100&wtLinkName=Subscribenow&wtLinkLoc=RN
https://www.wireless.miau.com/business/phones/phone_details_main.jsp?_DARGS=/business/templates/od_page_begin.jsp.pageLogoutForm
https://www.wireless.miau.com/business/policies/site_access.jsp;dsessionid=EBS51RW00NBS3B4R0ENCFEY?wtLinkName=TermsOfUse&wtLinkLoc=FTR
https://www.wireless.miau.com/business/shop/shop_cru_home.jsp?_DARGS=/business/shop/shop_cru_home.jsp.form_1
https://www.wireless.miau.com/pct/contract_acceptance/agreement.jsp?_DARGS=/pct/contract_acceptance/business_agreement_frag.jsp.pageBusinessForm
https://xdme.wireless.miau.com/jsp/login/login.jsp?Exp=Y&FP=Y
https://youachieve.miau.com/news.cfm?id=1204
https://youachieve.miau.com/news.cfm?id=1214
And I want this output:
https://www.wireless.miau.com/business/index.jsp?_requestid=839
https://www.wireless.miau.com/business/index.jsp?source=EENT042114500148N&_requestid=26&wtSlotClick=1-006Y3D-1-4&rel=nofollow
https://www.wireless.miau.com/business/index.jsp?token=46e134202bdd498c3369812e93c040122ecaf6b3
https://www.wireless.miau.com/business/index.jsp?token=Ae18464df3d728b2aa98286e843cd38cfa82c49d1&B2B_GTM=
https://www.wireless.miau.com/business/optin/optInEmailPopup.jsp?displayMode=1&from=businessCenter&bref=IBD903j370921100&wtLinkName=Subscribenow&wtLinkLoc=RN
https://www.wireless.miau.com/business/phones/phone_details_main.jsp?_DARGS=/business/templates/od_page_begin.jsp.pageLogoutForm
https://www.wireless.miau.com/business/policies/site_access.jsp;dsessionid=EBS51RW00NBS3B4R0ENCFEY?wtLinkName=TermsOfUse&wtLinkLoc=FTR
https://www.wireless.miau.com/business/shop/shop_cru_home.jsp?_DARGS=/business/shop/shop_cru_home.jsp.form_1
https://www.wireless.miau.com/pct/contract_acceptance/agreement.jsp?_DARGS=/pct/contract_acceptance/business_agreement_frag.jsp.pageBusinessForm
https://xdme.wireless.miau.com/jsp/login/login.jsp?Exp=Y&FP=Y
https://youachieve.miau.com/news.cfm?id=1204
I want to eliminate those that have several URLs with the same parameter but different values, I am trying this:
sort -u -t "=" -k1
and this:
sort -u -t "=" -k2
But I don't happen to succeed. Thank you very much
sort -u -t "=" -k1,1
will do what you want. The ,1 tells sort to stop at key position 1 too for the key. Default would be end-of-line, not end of field.
Given the following list:
colors=['#c85200','#5f9ed1','lightgrey','#ffbc79','#006ba4','dimgray','#ff800e','#a2c8ec'
,'grey','salmon','cyan','silver']
And this list:
Hospital=['a','b','c','d']
After I get the number of colors based on the length of the list - 'Hospital':
num_hosp=len(Hospital)
colrs=colors[:num_hosp]
colrs
['#c85200', '#5f9ed1', 'lightgrey', '#ffbc79']
...and zip the lists together:
hcolrs=zip(Hospitals,colrs)
Next, I'd like to be able to select 1 or more colors from hcolrs if given a list of one or more hospitals from 'Hospitals'.
Like this:
newHosps=['a','c'] #input
newColrs=['#c85200','lightgrey'] #output
Thanks in advance!
Pass the result of zip to the dict constructor to make lookup simple/fast:
# Don't need to slice colors; zip stops when shortest iterable exhausted
hosp_to_color = dict(zip(Hospitals, colors))
then use it:
newHosps = ['a','c']
newColrs = [hosp_to_color[h] for h in newHosps]
When adding a global variable to a list, does vim add this variable as a dynamic list?
input:
g:ListTotal = []
let g:mylist = ['hi','2','','']
call add(g:ListTotal, g:mylist)
echo g:ListTotal --> ['hi','2','',''] => ok
Then in a script g:mylist is changed p.e.
let g:mylist[0] = 'hello'
echo g:mylist --> = ['hello','2','',''] => ok
adding again this list to g:ListTotal:
call add(g:ListTotal, g:mylist)
:echo g:ListTotal -->
Output::
[['hello','2','',''],['hello','2','','']]
Expected output:
[['hi','2','',''],['hello','2','','']]
Does vim dynamically update lists when they're added to another list?
How can I add a list statically to another list?
I believe list variables are just pointers to the list so adding to list just add that pointer which is why changing looks like it changes both.
If you want a unique list you can copy the list.
call add(g:ListTotal, copy(g:mylist))
Or
call add(g:ListTotal, deepcopy(g:my list))
Read :h copy() and :h deepcopy().
I have a script which includes the following step as the first step in a series of filters of genomics data:
--option ~/folder$1/file$1 --option2 ~/folder$1/file$1 --indv NA12775 --options...
The script already uses a for-loop to go through folder/file indices 1-22. The option --indv takes a string, which is an identifiers. I have a separate list file which is just a column of "indv" identifiers:
NA06984
NA06986
NA06989
NA06994
NA07000
I have many such lists and I am looking for a solution to automatically take a single identifier from my list file, run the filtering script for "indv X" and then take the next consecutive identifier and repeat. Something like "for line in ID-list, run filter-script"...
You can use xargs for this:
xargs -I {} ./myprogram --indv {} < indvlist.txt
A couple bash methods for doing this:
for indv in $(<list-of-indv-values.txt)
do
something something .... ${indv} .....
done
or
while read indv
do
something something ... ${indv} .....
done < list-of-indv-values.txt