How to delete contents of a file based on line numbers?

Hi All

Can someone please help with how to delete specific line numbers from within a file?

What I need to do is delete the line numbers 13 and 32

Line number
1 {
2 "checksum": "d144cb6f1255ff4041579855b40de2ab",
3 "roots": {
4 "bookmark_bar": {
5 "children": [ {
6 "children": [ {
7 "date_added": "13249054777883609",
8 "guid": "95f3f891-5fbd-4dae-8cba-368c1472d894",
9 "id": "3",
10 "name": "Cardea",
11 "show_icon": false,
12 "source": "import_fre",
13 "type": "url",
14 "url": "https://www.cardea.nhs.uk/cardea/"
15 }, {
16 "date_added": "13249054777916773",
17 "guid": "b6d814ad-0ffe-43fc-b402-f59df0eeab12",
18 "id": "4",
19 "name": "Current Health",
20 "show_icon": false,
21 "source": "import_fre",
22 "type": "url",
23 "url": "https://web.currenthealth.com/"
24 }, {
25 "date_added": "13249054777951948",
26 "guid": "3cbc18bc-f251-494d-b60a-3c93d90eabc7",
27 "id": "5",
28 "name": "Datix Web",
29 "show_icon": false,
30 "source": "import_fre",
31 "type": "url",
32 "url": "https://datix.oxleas.nhs.uk/datix/live/index.php"
As a test I tried the below..but no result:

$LineNumber = 13
$Contents = Get-Content “$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks”
$Contents -replace $Contents[$LineNumber -1],“” | Set-Content Bookmarks

Many thanks for any assistance

One possible solution could be something like this:

$DeleteLines = 13,32
$Content = Get-Content -Path "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"
$Index = 1
$Output = 
foreach($Line in $Content){
  if($Index -notin $DeleteLines){
    $Line
  }
  $Index ++
}
$Output

You could use Select-String as that has a line number property.

 

$linesToDelete = 13,32
Select-String -Path .\myfile.txt -Pattern '.' | Where-Object {$_.Line -notin $linesToDelete} | 
	   Select-Object -ExpandProperty Line | Set-Content .\newfile.txt

This can be all on one line but I split it at the pipe ‘|’ for readability on the forum.

Hi Olaf

That works…thank you.

However I couldn’t get it to save ie on the last line ( why is that?):

$Output | Set-Content Bookmarks

The below did work

$Output | Set-Content “$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks”

Hi Matt

I would love to know the one liner method too, how can I point to the path using the environment variable pls?

As the below points is to windows \system32

$linesToDelete = 13,32
Select-String -Path ."$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -Pattern ‘.’ | Where-Object {$_.Line -notin $linesToDelete} | Select-Object -ExpandProperty Line | Set-Content .\Bookmarks

Sorry, for lack of clarity. My solution was two lines, but lines 2 and 3 can be all on one line; they were just split up for readability. You could do it all one one line without the $linesToDelete variable though and just put your paths in.

Select-String -Path "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -Pattern ‘.’ |
    Where-Object {$_.Line -notin 13,32} |
        Select-Object -ExpandProperty Line | 
            Set-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"

 

Hey Matt

So using the below (on 2 lines )it runs with no errors but it does not delete anything?

Line number
1 $linesToDelete = 13
2 Select-String -Path "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -Pattern '.' | Where-Object {$_.Line -notin $linesToDelete} | Select-Object -ExpandProperty Line | Set-Content .Bookmarks
When I use the one line, I get the following error:

Set-Content : The process cannot access the file ‘C:\Users\BIRIAHS\AppData\Local\Microsoft\Edge\User
Data\Default\Bookmarks’ because it is being used by another process.
At line:1 char:174

Another question…in case the files do not have the same line numbers across the board:

How would I be able to do: if the below exists, then delete the line above?

https://www.cardea.nhs.uk/cardea/

Edit…I now know the line numbers are different…so this has become a different beast.

I’ll post a new thread…am still interested in the one liner for future reference please.

Something else has the file open, maybe Edge or are you editing it in Notepad to see the changes? You shouldn’t see that error with Get-Content / Set-Content - at least, I didn’t when I tested.

No I made sure it was all closed…ie browser and notepad.

Interestingly Olaf’s method works but does not throw up the same error…even if the browser and notepad file is open.

On another note, I did post the new thread, but it states awaiting approval…could be cause the title is similar.

Do you happen to know, the answer on the new beast question?

That’s a bit harder. You’ll have to use a regex, I think. Something like this:

(Get-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -raw) -replace '((.*\n){1}(?=https\:\/\/www\.cardea\.nhs\.uk\/cardea\/))' | 
    Set-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"

 

Appreciate the help Matt

It ran with no errors but did not delete the “type”: “url” (the line above the url)

To explain a little clearer:

So in my example… if I want to delete the url on line 14…I actually need to delete line 13, otherwise the url gets recreated and I need to do this for multiple urls; unfortunately the line above always has the same info ie “type”: “url”

OK, that’s because in your post you just put the URL text, but the regex won’t match that because your data is actually

“url”: Cardea

Try this:

(Get-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -raw) -replace '((.*\n){1}(?=\"url\"\: https://www.cardea.nhs.uk/cardea/))' | 
    Set-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"

It works OK with a test file.

 

Apologies Matt, I should have made that clearer…really appreciate the help.

I tried the new command…It runs without errors and the notepad file detects a change and prompts to reload…but it seems no changes were actually made ?..I can sense…it is very close to a solution.

I also tried closing the notepad and browser…but no change.

Also…could you please give me an example of how to achieve the same for multiple url’s…rather than reproducing the same command for each url.

ie if I want to remove the lines above , lines 14 and 23 :

“url”: “https://www.cardea.nhs.uk/cardea/&#8221

“url”: “https://web.currenthealth.com/”

I seem to have lost some of the escape characters in the answer which might be why it’s not working as expected.

You can separate the regular expressions you want to match with ‘|’ (not to be confused with PowerShell’s pipe).

In my test file this correctly removes test2, test4, and test 6.

Test data:

test1
test2
"url": "https://www.cardea.nhs.uk/cardea/"
test3
test4
"url": "https://www.cardea.nhs.uk/cardea/"
test5
test6
"url": "https://web.currenthealth.com/"
test7

Code:

(Get-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -raw) -replace '(.*\n){1}(?=\"url\"\: \"https\:\/\/www.cardea.nhs.uk\/cardea\/\")|(.*\n){1}(?=\"url\"\: \"https\:\/\/web\.currenthealth\.com\/\")' |
 Set-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"

 

In your other thread Mike R makes a good point about using PowerShell’s native JSON capabilities to work with the file. If it is indeed JSON, that’s probably the avenue I would pursue rather than faffing about with regex.

 

Hi Matt

You are an absolute legend!

I’ve replied to Mike, his option would not work as I need to delete the url’s that I deployed but retain the ones that staff have personally saved.

Thank you for your example, I noticed on your example that you had no spaces before the url…where as my file does… I didn’t think that would matter.

Apologies as I have only just discovered the text code snippet…the option seems to come and go…known issue?

So using the below, it works perfect!

(Get-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -raw) -replace '(.*\n){1}(?=\               "url\"\: \"https\:\/\/www.cardea.nhs.uk\/cardea\/\")|(.*\n){1}(?=\               "url\"\: \"https\:\/\/web\.currenthealth\.com\/\")' | Set-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"

So almost there now...can you please help with an easier way than be typing in 15 spaces for each url ?
My actual file is as below:
{
   "checksum": "2abd029f28a5e701f690a90eda27280c",
   "roots": {
      "bookmark_bar": {
         "children": [ {
            "children": [ {
               "date_added": "13256332009828175",
               "guid": "a6bc023d-7216-4ebf-ae2a-c6d78e6ed972",
               "id": "6",
               "name": "Cardea",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://www.cardea.nhs.uk/cardea/"
            }, {
               "date_added": "13256332009671878",
               "guid": "997d28dc-67df-4e8a-b701-7a2eb3eff44c",
               "id": "7",
               "name": "CMC",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://cmc.learning.intersystems.com/"
            }, {
               "date_added": "13256332009734395",
               "guid": "11103d95-c8da-4c27-9826-8f149a5a3704",
               "id": "8",
               "name": "CPIP-SE Database",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://hic.tayside.scot.nhs.uk/cpipse"
            }, {
               "date_added": "13256332009968842",
               "guid": "106ec0ca-9c76-4b85-af5a-df4f41f791d3",
               "id": "9",
               "name": "Current Health",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://web.currenthealth.com/"
            }, {
               "date_added": "13256332010040489",
               "guid": "05b542ec-ff2a-431d-a432-5d6f5565f714",
               "id": "10",
               "name": "Datix Web",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://datix.oxleas.nhs.uk/datix/live/index.php"
            }, {
               "date_added": "13256332010321821",
               "guid": "bcb40895-5080-4270-9924-2fdc416be849",
               "id": "11",
               "name": "Easy Read Letters",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://www.easyreadappointmentletter.co.uk/oxleas-letter"
            }, {
               "date_added": "13256332010399970",
               "guid": "d7c657d7-2a60-4913-905d-3a853244c79a",
               "id": "12",
               "name": "Electronic PaySlips",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://my.esr.nhs.uk/"
            }, {
               "date_added": "13256332010181154",
               "guid": "b81ebcd4-02f6-410c-a4aa-22c9008af0c0",
               "id": "13",
               "name": "EOL",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://onft.allocate-cloud.co.uk/EmployeeOnlineHealth/ONFTLIVE/Login"
            }, {
               "date_added": "13256332010118638",
               "guid": "b5d41529-24e6-4c45-8d53-c734a22665da",
               "id": "14",
               "name": "E-Series",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://integraweb.oxleas.nhs.uk/eseries/esr.elogin"
            }, {
               "date_added": "13256332010243671",
               "guid": "1f19e655-f076-4439-968c-af74e95c566d",
               "id": "15",
               "name": "ESR",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://my.esr.nhs.uk/"
            }, {
               "date_added": "13256332010469523",
               "guid": "d23c36fc-aa10-494c-9d41-f5e5d944b1ad",
               "id": "16",
               "name": "Frameworki",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://frameworki.royalgreenwich.gov.uk/fwlive/"
            }, {
               "date_added": "13256332010532043",
               "guid": "e2ad06f3-a5e5-419c-91ff-42d4ab5d3914",
               "id": "17",
               "name": "Go 2 Book",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://www.go2book.co.uk/"
            }, {
               "date_added": "13256332010610189",
               "guid": "178731b8-2a41-4f23-b7d1-b44e1edc4873",
               "id": "18",
               "name": "HealthRoster Cloud",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://onft.allocate-cloud.co.uk/HealthRoster/ONFTLIVE/Login.aspx?Client=Air"
            }, {
               "date_added": "13256332010844639",
               "guid": "17cdc8c4-3a84-4131-99e6-16bd33d1ad64",
               "id": "19",
               "name": "Iaptus Remote",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://tokens.iaptus.co.uk/"
            }, {
               "date_added": "13256332010750858",
               "guid": "f26a955e-54fd-4370-b9b1-15659214aeb6",
               "id": "20",
               "name": "Iaptus",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://oxleas.iaptus.nhs.uk/"
            }, {
               "date_added": "13256332013860625",
               "guid": "738df45d-b0fe-43b3-8607-fc467079fdcf",
               "id": "21",
               "name": "iFox Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://biapps.int.oxleas.nhs.uk/iFOx/"
            }, {
               "date_added": "13256332010922785",
               "guid": "7b04ce4c-b6e0-456c-a2af-f765888623ec",
               "id": "22",
               "name": "Interpreting Service",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://oxleas.languageconnect.net/"
            }, {
               "date_added": "13256332010688338",
               "guid": "c7225e51-fd8e-4d1b-9a04-94ac109020d4",
               "id": "23",
               "name": "IT Helpdesk",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://servicedesk.oxleas.nhs.uk/LiveTime/WebObjects/LiveTime"
            }, {
               "date_added": "13256332011016565",
               "guid": "793ece12-7335-476f-b222-4f206deb1d90",
               "id": "24",
               "name": "Life Qi",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://uk.lifeqisystem.com/login/"
            }, {
               "date_added": "13256332011113690",
               "guid": "e7cdd986-3721-4119-abcd-7804587bb64c",
               "id": "25",
               "name": "Liquid Logic",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://10.212.186.103:10000/web/login.htm"
            }, {
               "date_added": "13256332011187927",
               "guid": "7910dad3-a190-4f34-9155-fae7d8f93b73",
               "id": "26",
               "name": "Micro Focus Filr",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://myfiles.oxleas.nhs.uk/"
            }, {
               "date_added": "13256332011406744",
               "guid": "3aeb4cdb-19ab-493a-8dfc-a64c86226a69",
               "id": "27",
               "name": "NHS e-Referral",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://nww.ebs.ncrs.nhs.uk/app-ebs/login.do"
            }, {
               "date_added": "13256332011344229",
               "guid": "ab6cecf8-df8f-4aaa-8599-4974230c25a7",
               "id": "28",
               "name": "NHS Mail Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://portal.nhs.net/"
            }, {
               "date_added": "13256332011250446",
               "guid": "007da5df-af3f-45c8-9dfd-9c3c7b36277b",
               "id": "29",
               "name": "NHS Mail",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://email.nhs.net/owa/@nhs.net"
            }, {
               "date_added": "13256332011516151",
               "guid": "668417a5-c787-4334-a72b-8e9a5d96ed82",
               "id": "30",
               "name": "Oxleas Audit Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://www.snapsurveys.com/wh/s.asp?k=151488852207"
            }, {
               "date_added": "13256332011625561",
               "guid": "adaf14ef-f0f3-40e1-92a5-7e4d539e8e6f",
               "id": "31",
               "name": "Oxleas Connect",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://connect.oxleas.nhs.uk/ssf/a/do?p_name=ss_forum&p_action=1&binderId=126&entityType=folder&action=view_permalink&novl_url=1&novl_landing=1?novl_root=1#1485859645564"
            }, {
               "date_added": "13256332011703715",
               "guid": "19ecebd4-61a5-4861-a944-dcf66415e5c8",
               "id": "32",
               "name": "Oxleas IDM",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://identity.oxleas.nhs.uk/IDM/portal/cn/GuestContainerPage/Oxleas_Welcome;jsessionid=7C9D75FE8C8F2EC96BAB5C24170488E1"
            }, {
               "date_added": "13256332011750600",
               "guid": "2ca54183-d508-4577-9e76-53640c5bd9e1",
               "id": "33",
               "name": "Oxleas Learning",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://learning.oxleas.nhs.uk/login/index.php"
            }, {
               "date_added": "13256332011844379",
               "guid": "dfa7d285-1a6a-4365-9d61-6368d08bb3d9",
               "id": "34",
               "name": "PathEKS Home (healthit.org.uk)",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://oxleas.healthit.org.uk/patheks"
            }, {
               "date_added": "13256332011953785",
               "guid": "1447060e-ece3-4880-ac72-b8af8a3eadd6",
               "id": "35",
               "name": "SARD Doctors",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://oxleas.sardjv.co.uk/"
            }, {
               "date_added": "13256332012031936",
               "guid": "7ac992a5-2cc3-4b8d-af53-a4ff7e2ef205",
               "id": "36",
               "name": "SARD Nurses",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://oxleas.nmcrevalidation.co.uk/users/sign_in"
            }, {
               "date_added": "13256332012110083",
               "guid": "1dc1ff83-f16d-47ad-af68-d64866919cf6",
               "id": "37",
               "name": "SBS Payroll & Pensions Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://nhssbs.microsoftcrmportals.com/"
            }, {
               "date_added": "13256332012188230",
               "guid": "3638f442-bb6a-4236-8bae-f1faa71a92e5",
               "id": "38",
               "name": "SLaM ePJS",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://slmhpepjs.slam.nhs.uk/EPJS"
            }, {
               "date_added": "13256332012266379",
               "guid": "479063ca-e615-4d3b-b407-c566235591d0",
               "id": "39",
               "name": "SpeakinConfidence",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://speak2us.at/oxleas"
            }, {
               "date_added": "13256332012360166",
               "guid": "78f8a5ba-6bbf-42f1-9f8d-4f8b28b36273",
               "id": "40",
               "name": "Spine Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://portal.national.ncrs.nhs.uk/portal/dt"
            }, {
               "date_added": "13256332012438307",
               "guid": "cbfec8f0-b70f-4323-ab23-824490ef2f41",
               "id": "41",
               "name": "TCES Community Configurator",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://tcesconfigurator.pro-cloud.org/"
            }, {
               "date_added": "13256332012516457",
               "guid": "d6e97f06-ca4e-4bab-bb6e-022b46a2cab7",
               "id": "42",
               "name": "TCES Community Prescriber Ordering",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://tcesconnections.pro-cloud.org/DefaultProCloud.aspx"
            }, {
               "date_added": "13256332012625864",
               "guid": "3b3e54cc-6921-4c3e-8f32-f15d961ef2e8",
               "id": "43",
               "name": "The Ox",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://theox.oxleas.nhs.uk/#"
            }, {
               "date_added": "13256332012766531",
               "guid": "db57fdec-acec-4a01-8dbd-18cb263787b5",
               "id": "44",
               "name": "Trac",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://admin.trac.jobs/login"
            }, {
               "date_added": "13256332013047871",
               "guid": "99678792-4749-4268-8815-7987084c326a",
               "id": "45",
               "name": "Xerox Hybrid Mail",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://hybridmail.int.oxleas.nhs.uk/"
            }, {
               "date_added": "13256332013985651",
               "guid": "4d938166-e6c4-4ee8-b9c5-b9c9ec742dd8",
               "id": "46",
               "name": "PRUH Pathology",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://dh-review.kingsch.nhs.uk/review/login.aspx"
            }, {
               "date_added": "13256332008999796",
               "guid": "111a5e5e-666c-4f7a-a0f2-c6f020d356b7",
               "id": "47",
               "name": "CAMHS POd",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://pod-database.org/p6/pod/"
            }, {
               "date_added": "13256332012938458",
               "guid": "d269fdf2-6a7a-4a28-9d81-84764fff2488",
               "id": "48",
               "name": "Windip",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://windip.oxleas.nhs.uk/e-windip/logon.aspx?ReturnUrl=%2fe-windip%2fdefault.aspx"
            } ],
            "date_added": "13256332709092599",
            "date_modified": "0",
            "guid": "17cc4533-868e-439d-98b8-5c3649e16e8c",
            "id": "5",
            "name": "Oxleas Favorites",
            "source": "import_fre",
            "type": "folder"
         } ],
         "date_added": "13256332703603281",
         "date_modified": "0",
         "guid": "00000000-0000-4000-a000-000000000002",
         "id": "1",
         "name": "Favourites bar",
         "source": "unknown",
         "type": "folder"
      },
      "other": {
         "children": [ {
            "children": [ {
               "date_added": "13256332014181256",
               "guid": "97a96408-e12d-45cf-afc2-18d28886efdf",
               "id": "50",
               "name": "CAMHS Pod",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://pod-database.org/p6/pod/"
            }, {
               "date_added": "13256332014525110",
               "guid": "97b57a79-d5e9-456c-a5cc-035d999a3903",
               "id": "51",
               "name": "Cardea",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://www.cardea.nhs.uk/cardea/"
            }, {
               "date_added": "13256332014337550",
               "guid": "3a8b6378-15f8-49c7-8a22-62256240bad0",
               "id": "52",
               "name": "CMC",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://cmc.learning.intersystems.com/"
            }, {
               "date_added": "13256332014462588",
               "guid": "b91f230f-323e-48db-9c63-1b805d8f7f50",
               "id": "53",
               "name": "CPIP-SE Database",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://hic.tayside.scot.nhs.uk/cpipse"
            }, {
               "date_added": "13256332014571998",
               "guid": "977cb273-99c7-4b21-a815-1a72e96d61db",
               "id": "54",
               "name": "Current Health",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://web.currenthealth.com/"
            }, {
               "date_added": "13256332014618897",
               "guid": "cb4306b5-588a-45f5-9937-51d2c1f3812e",
               "id": "55",
               "name": "Datix Web",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://datix.oxleas.nhs.uk/datix/live/index.php"
            }, {
               "date_added": "13256332014837702",
               "guid": "7cab181f-93a5-45c5-9b41-65bb7a873958",
               "id": "56",
               "name": "Easy Read Letters",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://www.easyreadappointmentletter.co.uk/oxleas-letter"
            }, {
               "date_added": "13256332014900228",
               "guid": "4f197a2e-6bd1-4332-a362-9d951b997b52",
               "id": "57",
               "name": "Electronic PaySlips",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://my.esr.nhs.uk/"
            }, {
               "date_added": "13256332014728297",
               "guid": "cc6f3496-3daf-4547-ab79-d1074f171df6",
               "id": "58",
               "name": "EOL",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://onft.allocate-cloud.co.uk/EmployeeOnlineHealth/ONFTLIVE/Login"
            }, {
               "date_added": "13256332014681405",
               "guid": "77382b43-7be4-4a67-bd98-99e25ddd7be8",
               "id": "59",
               "name": "E-Series",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://integraweb.oxleas.nhs.uk/eseries/esr.elogin"
            }, {
               "date_added": "13256332014790816",
               "guid": "09746b8d-503b-440f-a5dd-a427cec658b7",
               "id": "60",
               "name": "ESR",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://my.esr.nhs.uk/"
            }, {
               "date_added": "13256332014962739",
               "guid": "f2245413-a270-4ef9-90fb-f38915ff06f6",
               "id": "61",
               "name": "Frameworki",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://frameworki.royalgreenwich.gov.uk/fwlive/"
            }, {
               "date_added": "13256332015040897",
               "guid": "5a4abdb4-4a75-46cb-ab59-c0806db3a21d",
               "id": "62",
               "name": "Go 2 Book",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://www.go2book.co.uk/"
            }, {
               "date_added": "13256332015119039",
               "guid": "b3cf1cc3-e621-42b3-a6c3-6e7f8c4dcc7f",
               "id": "63",
               "name": "HealthRoster Cloud",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://onft.allocate-cloud.co.uk/HealthRoster/ONFTLIVE/Login.aspx?Client=Air"
            }, {
               "date_added": "13256332015376507",
               "guid": "d5f7ec4d-0498-4d85-ae3f-906993ce6b0e",
               "id": "64",
               "name": "Iaptus Remote",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://tokens.iaptus.co.uk/"
            }, {
               "date_added": "13256332015296557",
               "guid": "59daacc6-db70-49cf-995e-e6e2a9462a72",
               "id": "65",
               "name": "Iaptus",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://oxleas.iaptus.nhs.uk/"
            }, {
               "date_added": "13256332018823219",
               "guid": "a1c9adfd-ce4d-48fe-b0ae-914d171bfd6b",
               "id": "66",
               "name": "iFox Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://biapps.int.oxleas.nhs.uk/iFOx/"
            }, {
               "date_added": "13256332015423402",
               "guid": "1bdf669a-ac4f-4181-a925-7716e2dab8ad",
               "id": "67",
               "name": "Interpreting Service",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://oxleas.languageconnect.net/"
            }, {
               "date_added": "13256332015181558",
               "guid": "291c9001-e1c1-4632-9038-1747344ae9d8",
               "id": "68",
               "name": "IT Helpdesk",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://servicedesk.oxleas.nhs.uk/LiveTime/WebObjects/LiveTime"
            }, {
               "date_added": "13256332015548450",
               "guid": "ea5514b1-f584-47f2-a827-540394731bce",
               "id": "69",
               "name": "Life Qi",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://uk.lifeqisystem.com/login/"
            }, {
               "date_added": "13256332015610953",
               "guid": "b60573cf-c57d-458f-bf9e-11c9b391f2b5",
               "id": "70",
               "name": "Liquid Logic",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://10.212.186.103:10000/web/login.htm"
            }, {
               "date_added": "13256332015704735",
               "guid": "7880476b-160a-45d5-8e05-32ca75dbd5a4",
               "id": "71",
               "name": "Micro Focus Filr",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://myfiles.oxleas.nhs.uk/"
            }, {
               "date_added": "13256332016017329",
               "guid": "4fc71393-28fe-4388-a364-29620c2dd729",
               "id": "72",
               "name": "NHS e-Referral",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://nww.ebs.ncrs.nhs.uk/app-ebs/login.do"
            }, {
               "date_added": "13256332015907922",
               "guid": "b0f17282-8ec0-4c6c-8058-f27d261b4b70",
               "id": "73",
               "name": "NHS Mail Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://portal.nhs.net/"
            }, {
               "date_added": "13256332015751621",
               "guid": "50d9c55e-c45f-47f5-9461-1f7dd5a7558e",
               "id": "74",
               "name": "NHS Mail",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://email.nhs.net/owa/@nhs.net"
            }, {
               "date_added": "13256332016548741",
               "guid": "ca86a201-3b72-4c26-881d-4fb56317e268",
               "id": "75",
               "name": "Oxleas Audit Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://www.snapsurveys.com/wh/s.asp?k=151488852207"
            }, {
               "date_added": "13256332016658161",
               "guid": "721743f0-ece6-4c94-bd94-6ba960ddba51",
               "id": "76",
               "name": "Oxleas Connect",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://connect.oxleas.nhs.uk/ssf/a/do?p_name=ss_forum&p_action=1&binderId=126&entityType=folder&action=view_permalink&novl_url=1&novl_landing=1?novl_root=1#1485859645564"
            }, {
               "date_added": "13256332016939485",
               "guid": "4d108cba-7df9-450d-b148-e21a71f76d30",
               "id": "77",
               "name": "Oxleas IDM",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://identity.oxleas.nhs.uk/IDM/portal/cn/GuestContainerPage/Oxleas_Welcome;jsessionid=7C9D75FE8C8F2EC96BAB5C24170488E1"
            }, {
               "date_added": "13256332017119583",
               "guid": "1e0ebed7-d90d-40f3-b05f-13c792cea3f5",
               "id": "78",
               "name": "Oxleas Learning",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://learning.oxleas.nhs.uk/login/index.php"
            }, {
               "date_added": "13256332017166469",
               "guid": "5651e970-381f-4b3b-920e-4cf1cb2723c4",
               "id": "79",
               "name": "PathEKS Home (healthit.org.uk)",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://oxleas.healthit.org.uk/patheks"
            }, {
               "date_added": "13256332017525950",
               "guid": "51850e4e-5d81-4ded-b36e-e1a15761ee8d",
               "id": "80",
               "name": "SARD Doctors",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://oxleas.sardjv.co.uk/"
            }, {
               "date_added": "13256332017572840",
               "guid": "256cd3b8-3d33-44f4-9423-d869e1d54332",
               "id": "81",
               "name": "SARD Nurses",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://oxleas.nmcrevalidation.co.uk/users/sign_in"
            }, {
               "date_added": "13256332017619729",
               "guid": "2ab872a1-ad84-4ddd-aa0f-b3076b755f75",
               "id": "82",
               "name": "SBS Payroll & Pensions Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://nhssbs.microsoftcrmportals.com/"
            }, {
               "date_added": "13256332017682247",
               "guid": "4f936098-af81-49f3-8922-21fe16d32b09",
               "id": "83",
               "name": "SLaM ePJS",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://slmhpepjs.slam.nhs.uk/EPJS"
            }, {
               "date_added": "13256332017885442",
               "guid": "ce880a4d-5c12-4482-bd38-956d96376939",
               "id": "84",
               "name": "SpeakinConfidence",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://speak2us.at/oxleas"
            }, {
               "date_added": "13256332018057368",
               "guid": "cafe0dde-f39d-4c05-8b00-faebec3f3e3e",
               "id": "85",
               "name": "Spine Portal",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://portal.national.ncrs.nhs.uk/portal/dt"
            }, {
               "date_added": "13256332018119884",
               "guid": "74ea2a62-0ca6-44b9-9b53-c5700d2e0e6d",
               "id": "86",
               "name": "TCES Community Configurator",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://tcesconfigurator.pro-cloud.org/"
            }, {
               "date_added": "13256332018244921",
               "guid": "e5afd4a2-ed96-4251-93b1-b48742102860",
               "id": "87",
               "name": "TCES Community Prescriber Ordering",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://tcesconnections.pro-cloud.org/DefaultProCloud.aspx"
            }, {
               "date_added": "13256332018338698",
               "guid": "85ef7410-4d2c-4300-a674-496642b4f8d9",
               "id": "88",
               "name": "The Ox",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://theox.oxleas.nhs.uk/#"
            }, {
               "date_added": "13256332018401220",
               "guid": "76f1d3f3-77d4-4143-adf5-d3c6c0059836",
               "id": "89",
               "name": "Trac",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://admin.trac.jobs/login"
            }, {
               "date_added": "13256332018479368",
               "guid": "42a3153b-e633-43ef-a3a0-441a79d5165f",
               "id": "90",
               "name": "WinDip",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://windip.oxleas.nhs.uk/e-windip/logon.aspx?ReturnUrl=%2fe-windip%2fdefault.aspx"
            }, {
               "date_added": "13256332018635662",
               "guid": "ee7f49fa-3e78-44e7-b067-cee5f5783a2a",
               "id": "91",
               "name": "Xerox Hybrid Mail",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "http://hybridmail.int.oxleas.nhs.uk/"
            }, {
               "date_added": "13256332019042041",
               "guid": "1c3a135b-0e52-4c30-8844-9a8b585deafb",
               "id": "92",
               "name": "PRUH Pathology",
               "show_icon": false,
               "source": "import_fre",
               "type": "url",
               "url": "https://dh-review.kingsch.nhs.uk/review/login.aspx"
            } ],
            "date_added": "13256332709098409",
            "date_modified": "0",
            "guid": "ff6d8222-196d-481d-9b56-12a07b87fdf4",
            "id": "49",
            "name": "Oxleas Favorites",
            "source": "import_fre",
            "type": "folder"
         } ],
         "date_added": "13256332703603328",
         "date_modified": "0",
         "guid": "00000000-0000-4000-a000-000000000003",
         "id": "2",
         "name": "Other favourites",
         "source": "unknown",
         "type": "folder"
      },
      "synced": {
         "children": [  ],
         "date_added": "13256332703603332",
         "date_modified": "0",
         "guid": "00000000-0000-4000-a000-000000000004",
         "id": "3",
         "name": "Mobile favourites",
         "source": "unknown",
         "type": "folder"
      }
   },
   "version": 1
}

Hi Matt

I did respond… but am awaiting a Mod to approve it.

Not sure if this will be posted before the other one.

As I said before you’re a legend!.. Mike’s method will not work in case…as user saved url will need to be retained…which I wont know the url info for.

Once I realised that there are 15 spaces before the text start on the url line, I put in the spaces manually for now and that works perfect.

Only 2 issues remain now:

Is there an easier way to add the 15 spaces?

Or even better can the deletion of the line occur if the below line has a partial match or contains part of the url?

ie to save me typing in the full urls as some urls are a ridiculous length eg:

"https://connect.oxleas.nhs.uk/ssf/a/do?p_name=ss_forum&p_action=1&binderId=126&entityType=folder&action=view_permalink&novl_url=1&novl_landing=1?novl_root=1#1485859645564"

If the partial or match part of the url is not an option, could you please explain the formatting, I don’t understand the formatting of when the // is needed, I applied the same principle you gave to the below but it obviously needs the slashes in a different way…I imagine the above url will also be a nightmare.

https://datix.oxleas.nhs.uk/datix/live/index.php

 

Reading Get-Help about_regular_expressions is a good starting point and you can use https://regex101.com/ to test them against your strings.

(Get-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks" -raw) -replace '(.*\n){1}(?=\s*\"url\"\: \"https\:\/\/www.cardea.nhs.uk\/cardea\/.*\")|(.*\n){1}(?=\s*\"url\"\: \"https\:\/\/web\.currenthealth\.com\/.*\")' | 
    Set-Content "$env:localappdata\Microsoft\Edge\User Data\Default\Bookmarks"

To add exactly 15 spaces, add \s{15} to the start of the expression. I think it would be wise to use \s* though, which matches 0 or more whitespace charaters.
To match any character, add .* after the slash after the domain name.
</span> is the regex escape character. While it’s not absolutely necessary before every symbol, I tend to escape all non-alphanumeric characters. Sharp eyes will notice I didn’t escape the periods in the URL in one of the examples…

In regex certain symbols have certain meanings. For example, . will match any character so to match a full stop instead of any character, we should escape it . .

Breakdown of one of the examples:

1. (.*\n){1}

match exactly one {1} instance of 0 or more characters .* ending in a new line \n

2.(?=

?= is the lookahead. Think of this as saying ‘I want to match everything that matches 1 and 3 but I only want to capture 1.’ This is why the expression replaces the line above the URL but not the line containing the URL.

3. \s*"url": "https://www.cardea.nhs.uk/cardea/.*")

match 0 or more whitespace characters \s*
followed by the string “url”: "Cardea
followed by 0 or more characters up to the quote mark. .*"

As discussed above, non alpha-numeric characters are preceded by the escape character </span>

Thank you for the detailed info…I shall absorb…very helpful indeed.