Find and copy word

KS1 Reading Find and Copy Resources

KS1 Reading Find and Copy a Word Test Practice

These KS1 Reading Find and Copy a Word worksheets will help your pupils to practise these question types from the SATs tests. This resource includes up to four different text types (narrative, diary extract, letter and newspaper report).

Not a member? Sign up here.

[apss_share]

What’s included in the pack?

This pack includes:

  • KS1 Reading Find and Copy a Word worksheets with answers.
  • Interactive PDF versions to use with Adobe Acrobat Reader

National Curriculum Objectives

English Year 1: Develop pleasure in reading, motivation to read, vocabulary and understanding by discussing word meanings, linking new meanings to those already known

English Year 2: Develop pleasure in reading, motivation to read, vocabulary and understanding by discussing and clarifying the meanings of words, linking new meanings to known vocabulary

Differentiation:

Beginner Includes 3 different text types (narrative, letter and diary entry) followed by 4 questions per text requiring children to find and copy a word from the text. Aimed at Year 1 Secure.

Easy Includes 3 different text types (narrative, letter and diary entry) followed by 6 questions per text requiring children to find and copy a word, or group of words, from the text. Aimed at Year 2 Developing.

Tricky Includes 4 different text types (narrative, letter, diary entry and newspaper report) followed by 8 questions per text requiring children to find and copy a word, or group of words, from the text. Aimed at Year 2 Secure.

This resource is available to download with a Premium subscription.

is there a posibility to find a word in a file and than to copy the following word?

Example:

abc="def"
bla="no_need"
line_i_need="information_i_need"
still_no_use="blablabla"

so the third line, is exactly the line i need!

is it possible to find this word with shell orders?

thanks for your support

asked May 24, 2015 at 16:43

Lama Dingo's user avatar

2

Using an awk with custom field separator it is much simpler:

awk -F '[="]+' '$1=="line_i_need"{print $2}' file
information_i_need

-F '[="]+' sets field separator as 1 or more of = or "

answered May 25, 2015 at 4:23

anubhava's user avatar

anubhavaanubhava

753k64 gold badges559 silver badges630 bronze badges

Use grep:

grep file_name line_i_need

It will print:

line_i_need="information_i_need"

answered May 24, 2015 at 16:49

diogo's user avatar

diogodiogo

691 silver badge8 bronze badges

1

This finds the line with grep an cuts the second column using " separator

 grep file_name line_i_need | cut -d '"' -f2

answered May 24, 2015 at 17:05

Michal Bureš's user avatar

3

Sub GoToAPageAndLine()'
' Makro created on 22.01.2013
'
    Dim TargetDocName, SearchTerm, MyString As String, TargetDoc As Document
    Dim PosDelimiter, PosMakroButton, Page, Line
    'Read Private Field which contains The Document Name
    MyString = Mid$(Selection.Fields(2).Code, 10)
    MyString = Left$(MyString, Len(MyString) - 1)
    PosDelimiter = InStr(MyString, "|")
    TargetDocName = Left$(MyString, PosDelimiter - 1)
    SearchTerm = Mid$(MyString, PosDelimiter + 1)
    'MsgBox TargetDocName
    'Read the MakroButton Text which contains Page Number and Line
    MyString = Mid$(Selection.Fields(1).Code, 1)
    PosMakroButton = InStr(MyString, "MACROBUTTON")
    MyString = Mid$(MyString, PosMakroButton + 32)
    PosDelimiter = InStr(MyString, ", ")
    Page = Left$(MyString, PosDelimiter - 1)
    Line = Mid$(MyString, PosDelimiter + 4)
    'MsgBox Page
    'MsgBox Line
    On Error GoTo Errhandler
    Set TargetDoc = Documents(TargetDocName)
    TargetDoc.Activate
    Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=Page, Name:=""
    If Line - 1 > 0 Then
        Selection.GoTo What:=wdGoToLine, Which:=wdGoToRelative, Count:=Line - 1, Name:=""
    End If
    If SearchTerm <> "" Then
        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = SearchTerm
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute
    End If
Errhandler:
    Select Case Err
        Case 4160: 'Error 4160 = Bad file name
            MsgBox "The file """ & TargetDocName & """ isn't open. Please open the file first."
    End Select
End Sub
Sub macrobutton(Page, Line As Integer, Filename, Searchterm As String)
'
' Makro created on 22.01.2013
'
    Dim oField As Field, MyRange As Range
    Set MyRange = Selection.Range
    Set oField = Selection.Fields.Add(Range:=MyRange, Type:=wdFieldEmpty, Text:= _
        "MACROBUTTON GoToAPageAndLine S. " & Page & ", Z. " & Line & "", PreserveFormatting:= _
        False)
    Set oRange = ActiveDocument.Range(oField.Code.Start + 1, oField.Code.Start + 1)
    ActiveDocument.Fields.Add Range:=oRange, Type:=wdFieldPrivate, Text:="" & Filename & "|" & Searchterm, PreserveFormatting:=False
End Sub
Sub CopyHighlightedTextInNewDocument()
'
' Makro created on 22.01.2013
'
    ActiveDocument.Range(0, 0).Select
    With Selection
        .Find.ClearFormatting
        .Find.Highlight = True
        With .Find
            .Replacement.ClearFormatting
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Set CurrentDoc = ActiveDocument
        Set NewDoc = Documents.Add(Visible:=False)
        NewDoc.Content.InsertAfter "Summary of the highlighted text in " & """" & CurrentDoc.Name & """"
        NewDoc.Content.Font.Bold = True
        NewDoc.Content.InsertParagraphAfter
        NewDoc.Content.InsertParagraphAfter
        .Find.Execute
        Dim PageNumber, LineNumber As Integer
        Do While .Find.Found
            .Select
            Selection.Copy
            PageNumber = .Information(wdActiveEndPageNumber)
            LineNumber = .Information(wdFirstCharacterLineNumber)
            NewDoc.Activate
            With Selection
              .EndKey Unit:=wdStory
              .Font.Bold = True
              .Font.Underline = True
              .Font.ColorIndex = wdDarkBlue
              Call macrobutton(PageNumber, LineNumber, CurrentDoc.Name, "")
              .Font.Bold = True
              .Font.Underline = False
              .Font.ColorIndex = wdBlack
              '.InsertAfter "S. " & PageNumber
              '.InsertAfter ", Z. " & LineNumber
              .TypeText "______________________________________________________________" & vbCr
              .InsertParagraphAfter
              .MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove
              .Paste
              .InsertParagraphAfter
              .InsertParagraphAfter
              .MoveDown Unit:=wdLine, Count:=2, Extend:=wdMove
            End With
            CurrentDoc.Activate
            .Find.Execute
        Loop
    End With
    NewDoc.Activate
    Options.ButtonFieldClicks = 1
    Selection.HomeKey Unit:=wdStory
    ActiveWindow.Visible = True
End Sub
Sub CopyKeywordPlusContext()
'
' Makro created on 22.01.2013
'
    Dim SearchTerm As String, WordsAfter As Long, WordsBefore As Long, i As Long
    Dim Rng As Range, Doc As Document, RngOut As Range
    SearchTerm = InputBox("Enter your search terms, Maria Cancro!" & vbCr & _
      "Then, sit back, relax, and let this macro do some heavy lifting." & vbCr & _
      vbCr & "It's okay - it works out!")
    SearchTerm = LCase(Trim(SearchTerm))
    If Len(SearchTerm) = 0 Then Exit Sub
    WordsBefore = InputBox("Enter the number of words before your search term to find.")
    WordsAfter = InputBox("Enter the number of words after your search term to find.")
    ActiveDocument.Range(0, 0).Select
    With Selection
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = SearchTerm
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .Execute
      End With
      If .Find.Found Then
        Set CurrentDoc = ActiveDocument
        Set Doc = Documents.Add(Visible:=False)
        Doc.Content.InsertAfter "Search results for """ & SearchTerm & """ + context in " & """" & CurrentDoc.Name & """"
        Doc.Content.Font.Bold = True
        Doc.Content.InsertParagraphAfter
        Doc.Content.InsertParagraphAfter
        Dim CheckAuto As Integer
        CheckAuto = MsgBox("Should all findings be copied automatically ('yes') or do you want to check each occurence manually ('no') ?", vbYesNo, "Automatically oder manually?")
        Dim CopyThis As Boolean
        Do While .Find.Found
          CopyThis = False
          Set Rng = .Range.Duplicate
          With Rng
            .Select
            Dim SelectionStart, SelectionEnd
            SelectionStart = Selection.Range.Start
            SelectionEnd = Selection.Range.End
            ActiveDocument.Range(SelectionStart, SelectionStart).Select
            Dim PageNumber, LineNumber As Integer
            PageNumber = Selection.Information(wdActiveEndPageNumber)
            LineNumber = Selection.Information(wdFirstCharacterLineNumber)
            .MoveStart wdWord, -WordsBefore
            .MoveEnd wdWord, WordsAfter + 2
            .Select
            Selection.MoveStart Unit:=wdLine, Count:=-1 'Comment this out if you 
            Selection.MoveEnd Unit:=wdLine, Count:=1    '                        don't want the selection to be extended to the start / end of line
            If CheckAuto = vbYes Then
                CopyThis = True
            Else
                Dim Check As Integer
                Check = MsgBox(.Text, vbYesNoCancel, "Copy this block?")
                If Check = vbCancel Then
                    Exit Do
                ElseIf Check = vbYes Then
                    CopyThis = True
                End If
            End If
            If CopyThis = True Then
              Selection.Copy
              Doc.Activate
              With Selection
                  .EndKey Unit:=wdStory
                  .Font.Bold = True
                  .Font.Underline = True
                  .Font.ColorIndex = wdDarkBlue
                  Call macrobutton(PageNumber, LineNumber, CurrentDoc.Name, SearchTerm)
                  .Font.Bold = True
                  .Font.Underline = False
                  .Font.ColorIndex = wdBlack
                  '.InsertAfter "S. " & PageNumber
                  '.InsertAfter ", Z. " & LineNumber
                  .TypeText "______________________________________________________________" & vbCr
                  .InsertParagraphAfter
                  .MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove
                  .Paste
                  .InsertParagraphAfter
                  .InsertParagraphAfter
                  .MoveDown Unit:=wdLine, Count:=2, Extend:=wdMove
              End With
              CurrentDoc.Activate
            End If
          End With
          .Collapse wdCollapseEnd
          .Find.Execute
        Loop
        Doc.Activate
      End If
    End With
    With Doc.Range.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = SearchTerm
      .Replacement.Text = "^&"
      .Replacement.Highlight = True
      .Forward = True
      .Wrap = wdFindStop
      .Format = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchAllWordForms = False
      .MatchSoundsLike = False
      .MatchWildcards = False
      .Execute Replace:=wdReplaceAll
    End With
    Options.ButtonFieldClicks = 1
    Selection.HomeKey Unit:=wdStory
    ActiveWindow.Visible = True
End Sub

Please Note:
This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Copying Found Items to a New Document.

Written by Allen Wyatt (last updated July 2, 2022)
This tip applies to Word 97, 2000, 2002, and 2003


Robert notes that Word allows him to locate and highlight all the instances of an item that he enters in the Find dialog box. He wonders if, from that point, there is some way he can select all the highlighted instances so that he can copy and paste them into a new document.

Copying individual items that are found is easy?all you need to do is have the source and target documents open, find what you want in the source document, copy it to the Clipboard, and then paste it into the target document. Copying a bunch of found items at once is a bit trickier, however. Here’s how to do it:

  1. Make sure you have the source and target documents both open, with the source document active.
  2. Press Ctrl+F. Word displays the Find tab of the Find and Replace dialog box. (See Figure 1.)
  3. Figure 1. The Find tab of the Find and Replace dialog box.

  4. In the Find What box enter what you want to search for.
  5. Set any other parameters you desire for your search.
  6. Make sure the Highlight All Items Found In check box is selected. (The drop-down list under the check box should be set to Main Document.)
  7. Click Find All. (If you don’t see a Find All button, it means you didn’t perform step 5.) Word selects all the matches it found.
  8. Click the title bar of your source document. This moves focus from the Find and Replace dialog box to the document itself, and all the selected items remain selected.
  9. Press Ctrl+C. This copies all the selected items to the Clipboard.
  10. Switch to the target document.
  11. Press Ctrl+V. Word pastes the Clipboard contents (all the matched information) into the target document.

WordTips is your source for cost-effective Microsoft Word training.
(Microsoft Word is the most popular word processing software in the world.)
This tip (3850) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Copying Found Items to a New Document.

Author Bio

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. Learn more about Allen…

MORE FROM ALLEN

Overcoming Automatic Word Selection

When you select text with the mouse, Word usually selects entire words for you. If you don’t want to do this, you can use …

Discover More

Diagonal Borders in a Conditional Format

Conditional formatting is a great tool for changing how your data looks based on the data itself. Excel won’t allow you …

Discover More

Accessing Paragraphs in a Macro

Need to process a document, paragraph by paragraph, in a macro? It’s easy to do once you understand that Word’s object …

Discover More

More WordTips (menu)

Replacing with a Subscript

The Find and Replace capabilities of Word are quite powerful. One type of replacing may not seem possible at …

Discover More

Removing HTTP from URLs

Having problems when it comes to replacing information in URLs? You’re not the only one; it can be confusing making mass …

Discover More

Keeping a Replace Operation Displayed

The Find and Replace tool is designed to help you find and replace information as quickly as possible. However, you may …

Discover More

INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Thanks. We have received your request and will respond promptly.

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!

  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It’s Free!

*Tek-Tips’s functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help with simple find and copy macro for Word

Need help with simple find and copy macro for Word

(OP)

21 Mar 12 07:51

I need to write a macro in Word to find and copy some text.  The text that I need to find is a URL in the source code from my company’s website.  The problem is that the URL changes everyday because it includes a time range.  I found that in the source code, just two lines below the URL that I need, is the rigname in a format that should never change.  Here is an example of the code that I will be working with.

CODE

<TD><IMG border=0 alt=»Daily Report» src=»images/daily_report.png» width=16 height=16>&nbsp;<A href=»GenericTxDReport.aspx?PageMode=Daily&amp;ScenarioId=55&amp;UtcTimeRange=1332133200000-1332219600000″><SMALL>Daily Report</SMALL></A>&nbsp;&nbsp;</TD>

<TD><IMG border=0 alt=Archive src=»images/archive.png» width=16 height=16>&nbsp;<A href=»Archive.aspx?RigName=Top+Secret&amp;ScenarioIds = 55,53,41,37″><SMALL>Archive</SMALL></A></TD></TR>

This is what I need to extract from the above code.

CODE

GenericTxDReport.aspx?PageMode=Daily&amp;ScenarioId=55&amp;UtcTimeRange=1332133200000-1332219600000

Is there anyway to extract just that portion of the code flawlessly?  I would like to stick it into an excel cell, because I have an automation program that really works wonders with excel.

One catch is that the URL changes from day to day (like I said up top), and I need to identify the URL by using the rig name.  To kill two birds with one stone, I would like to search for this code:

CODE

RigName=Top+Secret&amp;ScenarioId

and then, move the cursor up a couple of lines or something, and copy the URL.

I know this would be a peice of cake to someone out there, but I have struggled with it all day with no avail.  Thanks in advance.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Join Tek-Tips® Today!

Join your peers on the Internet’s largest technical computer professional community.
It’s easy to join and it’s free.

Here’s Why Members Love Tek-Tips Forums:

  • Tek-Tips ForumsTalk To Other Members
  • Notification Of Responses To Questions
  • Favorite Forums One Click Access
  • Keyword Search Of All Posts, And More…

Register now while it’s still free!

Already a member? Close this window and log in.

Join Us             Close

Like this post? Please share to your friends:
  • Find and circle the odd word out in each line
  • Find anagrams of a word
  • Find a word or expression in the text which is similar in meaning to
  • Find a word or an expression in the passage which means
  • Find a word on the web page