Get line that contains and then get the second and fourth line after that.

So I have a text file and I want it to find all the lines in the file that contain an @ symbol and then I want it to get that line and the line second and fourth from that line. Then I would export it like this:
$linewith@ + ":" + $secondline + ":" + $fourthline
Finding the lines with an @ symbol is easy, but how would I tell it to get the second and fourth line after the line with an @ symbol?
So I would get the lines with something like this:
foreach ($line in [System.IO.File]::ReadLines($filename)) {
if($line.contains("@")){}

That worked perfectly thanks man! Here is the entire code. I'm sure it could been cleaned up. I'm still learning powershell. 
$username = "Username"
$password = "Password"
$url = "http://URL"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate($url)
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value = "$username"
$ie.document.getElementById("password").value = "$password"
$ie.document.getElementById("click").click()
start-sleep 20
$ie.Document.body.innertext | Out-File -FilePath c:\web.txt
$links = $ie.Document.getElementsByTagName('A')
$logout = $links | where {$_.innerText -eq 'logout'}
$logout.click()
start-sleep 5
(gc C:\web.txt) | ? {$_.trim() -ne ""} | set-content C:\web.txt
( Get-Content C:\web.txt | Select-Object -Skip 2 | ForEach-Object { $_.TrimStart( " " ) } ) | Set-Content C:\web.txt
start-sleep 5
$fileContents = Get-Content C:\web.txt
foreach ($line in $fileContents) {
if ($line -like '*@*') {
$line + ":" + $($fileContents[$line.ReadCount+0]) + ":" + $($fileContents[$line.ReadCount+3]) | Out-File -FilePath c:\finish.txt -Append

Similar Messages

  • How do I get the iPad to work again after I have erased data (intentionally) and do not have my base computer to plug into to access itunes?

    How do I get the iPad to work again after I have erased data (intentionally) and do not have my base computer to plug into to access itunes?

    If you have iOS 5 installed on it, you don't need a PC.  simply turn it on and set it up.
    if you don't have iOS 5 then you'll need a computer.

  • I have been trying to get the full version of lightroom after using a trial version but it says something about "GB" ? And i need to log into different account or set up a new one? Please help?

    I have been trying to get the full version of lightroom after using a trial version but it says something about "GB" ? And i need to log into different account or set up a new one? Please help?

    I would love to give you more information but i cannot access that page again? i can add Lightroom to my cart but when i go into my cart it says there is nothing in there? I have a red bubble above "my cart" with a number 4 in it to show there is something there but there is not? It just wont let me buy anything?

  • How can I get the second group and report totals in Matrix report?

    Hi,
    I have created a matrix report with 2 break Groups.
    Iam getting columns totals for the first group, but not for the second group and the report totals.
    How can I get the second group and report totals for each month?
    Thanks.
    Ram.

    Hi Ram,
    If you want a total at any group-level, go to the particular group in the data model, insert a summary column in the group, and select
    Reset At > appropriate Group Name
    For report level summaries, you must create the summary column outside of all groups.
    Navneet.

  • Get the second last occurrence of character

    Hi
    I want to get the second last occurrence of "_" from the following string and then take the 3 characters before this.
    Does anyone know how to do it in a simple query?
    The string is
    ALS_AKM-G-2500_BASED_pre_paid_akm_mis_stv1

    user2360027 wrote:
    I wanted a simple query. The regular expressions are too much for me to understand :-)Not difficult at all:
    regexp_replace(txt, '.*(.{3})_[^_]*_.*$', '\1')
    \------------------/ \/\----/|\---/|\/|   \--/
             |           |    |  |  |  || |    |
             |           |    |  |  |  || |    and replace that found matching pattern with what is in backreference 1
             |           |    |  |  |  || |                                    (the 3 characters found in the pattern)
             |           |    |  |  |  || followed by the end of the string
             |           |    |  |  |  ||
             |           |    |  |  |  |followed by any characters
             |           |    |  |  |  |
             |           |    |  |  |  followed by an "_" character
             |           |    |  |  |
             |           |    |  |  followed by any number of non "_" characters
             |           |    |  |
             |           |    |  followed by an "_" character
             |           |    |
             |           |    followed by any 3 characters (mark as a back reference using brackets)
             |           |
             |           where it matches any number of characters
             |          
             replace the section of string txt

  • How do I get the second HD to be a shared network drive??

    PowerPC G5 / dual 2Ghz - used as our file server.
    running OS X Server - v.10.3.9
    Have one internal HD - 160GB partitioned into two drives (General Access & Archive) in the Public folder of this computer
    Appears as Network: Local / G5 Server. When you click the connect button you get a choice of which volume to mount/connect to (ie. General Access; Archive or both)
    Running out of space on the drive so I purchased a second 160GB HD. Installed it, formatted it (with DiskUtility), named it, and copied all files from Archive (partition)
    The thought is to make this new 160GB drive Archive and to remove the partition from the original 160GB HD and have that be just General Access.
    How do I get the second HD to be a shared network drive??
    Also can I remove the partition to the first without having to clone it and reformat?

    Roam & Ali B,
    Thanks!!
    Next dumb question(s).
    We have a laCie FW external HD that I was using as a back-up drive (temporarily)
    I do have some files on it that I have to bring back onto the server to use. I get a admin user&passsword prompt every time I have to copy something back. It usually copies over a locked file that can only be deleted from the Server terminal.
    1. Why isn't this working without the admin prompt? I used DiskUtil to format it before I could use it.
    2. How exactly do I "clone" the current content - its not a simple 'Select All' and drag&drop? Is it going to bring over the partition as well??
    3. Once I have everything on the FW HD, re-boot using it as the System, and re-format the original 160GB HD - will I run into #1.

  • How do I get the Blackberry symbol to show after I send a text message?

    How do I get the Blackberry symbol to show after I send a text message?

    Hi and welcome to the forums!
    Create an AutoText entry
    1. In the device options, click AutoText.
    2. Click the trackwheel.
    3. Click New.
    4. In the Replace field, type the text to replace.
    5. In the With field, perform one of the following actions:
    • Type replacement text.
    • To insert a macro (for example, the current date or time), click the trackwheel. Click Insert Macro.
    6. In the Using field, perform one of the following actions:
    • To capitalize the entry exactly as you typed it, click Specified Case.
    • To capitalize the entry according to the context, click SmartCase.
    7. Set the language.
    8. Click the trackwheel.
    9. Click Save.
    Thanks,
    Bifocals
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • When I open a new tab, how can I get the second tab to be me my home page also?

    I know how to right click and open a new tab when I am browsing but if I want to open just a blank new tab, how can I get the second tab to be my home page also?

    I know how to right click and open a new tab when I am browsing but if I want to open just a blank new tab, how can I get the second tab to be my home page also?

  • Why do I keep getting the windows messenger error even after disabling it?

    Hi,
         I am trying to download the flash player 10 on my windows XP computer. I get the error(s) close "Internet Explorer" and close "Windows messenger" during download. I closed Internet Explorer ok, but still keep getting the Windows messenger error even after stopping it and disabling it. I also have IT on medium and firewall and antivirus disabled.
       How do I fix this problem. Please help. I need a flash player for work...Thanks
    Nitrowizard88

    ok, Here is whats listed
    flash10l.oxc active x control
    flashinstall, log
    flashutil10l_activex.dll
    flashutil10l_activex.exe
    genuist.exe
    kb923789.inf
    install.log
    I think I am running IE7
    32 bit..not sure on this...

  • HT5664 Just bought a new IMAC. Cant get the iPhoto to open even after apparently loading the library upgraded. Ideas?

    Just bought a new IMAC. Cant get the iPhoto to open even after apparently loading the library upgraded. Ideas?

    Did you install and RUN the iPhoto Library Upgrader on your library?
    OT

  • HT204088 accidentally purchased the same app twice, charged twice, how do i get the second charge removed?

    I bought the same app twice accidentally, how do I get the second charge removed?

    Go to ... http://www.apple.com/emea/support/itunes/contact.html ... and beg.
    Likelyhood is, if they are convinced it was an accident they will refund.   But its not something you can rely on.

  • I get the little color wheel constantly after each mouse function is there a fix ?

    I get the little color wheel constantly after each mouse function is there a fix

    Sorry, this is not possible in the current version of Firefox, but we have an open bug report where we are tracking this issue here:
    https://bugzilla.mozilla.org/show_bug.cgi?id=686228
    With luck it will be fixed in a future version.

  • Issues with getting the slide button to work after upgrade to iOS 7.02 and 7.03

    Ever since upgrading to iOS 7.02 and 7.03 having issues with getting the slide button to work to open up iPad 2.  Happened last week and was able to restore it to new and get it to work again and it worked great until one week later (this morning) doing the same thing.  Have tried restoring iPad to new 3 times (via itunes) and still unable to get the slide button to move so can use the iPad.  IPad able to charge, able to restore, able to sync with itunes even able to recover but not able to get past first screen where you have to slide to access iPad.  Any help would be greatly appeciated.  Live about 300 miles from nearest Apple store.

    I am beginning to wonder whether there isn't some weird problem with that Home button.
    Try this: Settings > General > Accessibility > AssistiveTouch = On
    This will place a button on the iPad's screen.
    You can move this button anywhere on the screen.
    This button gives you - amongst many other things - a soft Home button.
    To turn your iPad on, you can use the Sleep/wake button or move a small magnet across the bezel of the iPad where the volume controls are.
    If you use the magnet, then: Settings > General > Lock / Unlock = On
    Now should not need to press the Home button anymore.
    If this method allows you to use your iPad without a hitch, then suspect hardware problems with the Home button.

  • Howto: comparing 2 dates and getting the seconds

    By comparing 2 dates I need to extract or get somehow the elapsed seconds. I need to get only
    the seconds.
    Dates are in this format "hh:mm:ss"
    I tried with Date and GregorianCalendar but I couldnt get the desired result.
    Can someone provide me with a sample code please.

    remus.dragos wrote:
    Its not broken, nor absurd or complicated. I only need resolution only for minutes. The method that I use does not need to know more than 20 seconds.
    But I added minutes knoledge aniway. As you can see its easy to add hour resolution if needed. But I didnt needed it so thats why I took that approach.
    This looks cleaner for you? I just wrote it here, untested, but should work.
    public int returnSeconds(Calendar c1, Calendar c2)
    int mins =  c1.get(Calendar.MINUTES) - c2.get(Calendar.MINUTES);
    int secs =  c1.get(Calendar.SECONDS) - c2.get(Calendar.SECONDS);
    if (mins > 0) return secs+=mins;
    else            return secs;
    }And why should I treat all the time as miliseconds since the epoch. Thats an absurd afirmation without a detailed explanation.
    Edited by: remus.dragos on Apr 30, 2008 6:18 AM- Unnecessary creation of expensive Calendar objects.
    - Significantly slower
    - Breaks across Timezones
    - Unnecessary decision making introduces complexity
    - Introduces a bug by assuming c1 represents a time greater than c2
    - Introduces a bug by not multiplying minutes by 60 to obtain seconds.
    - Makes assumptions about the calendar system in use
    - Less maintainable because it limits the scope of time unit resolution handled by the logic
    I probably missed some more too. None of this is needed, and it is very brittle. Your problem can be solved by subtracting one fixed-point number from another. Go with es5f's approach.

  • I am still getting the itunes sync error -50 after I deleted the ipad cache in finder.  Any other suggestions so that I can sync my iPad?

    I am geting an itunes errror -50 when trying to sync my ipad.  Itunes and apad are all currently up to date.  I read a question regarding this error that was from 2011 and I deleted the ipad cache in Finder as it suggested.  I still get the error message.  Any suggestions?

    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
    Update and restore alert messages on iPhone, iPad, and iPod touch
    http://www.buybuyla.com/tech/view/012953a0d412000e.shtml
    iOS: Resolving update and restore alert messages
    http://support.apple.com/kb/TS1275
    From the above link.
    Error 13, 14, 35 and 50 (or -50)
    These errors are typically resolved by performing one or more of the steps listed below:
        1.    Perform USB isolation troubleshooting, including trying a different USB port directly on the computer. See the advanced steps below for USB troubleshooting.
        2.    Put a USB 2.0 hub between the device and the computer.
        3.    Try a different USB 30-pin dock-connector cable.
        4.    Eliminate third-party security software conflicts.
        5.    There may be third-party software installed that modifies your default packet size in Windows by inserting one or more TcpWindowSize entries into your registry. Your default packet size being set incorrectly can cause this error. Contact the manufacturer of the software that installed the packet-size modification for assistance. Or, follow this article by Microsoft: How to reset Internet Protocol (TCP/IP) to reset the packet size back to the default for Windows.
        6.    Connect your computer directly to your Internet source, bypassing any routers, hubs, or switches. You may need to restart your computer and modem to get online.
        7.    Try to restore from another known-good computer and network.
    iPad: Unable to update or restore
    http://support.apple.com/kb/ht4097
     Cheers, Tom

Maybe you are looking for