Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Only typing certain parts of a text file  (Read 5400 times)

0 Members and 1 Guest are viewing this topic.

kamak

    Topic Starter


    Rookie

    Only typing certain parts of a text file
    « on: June 12, 2008, 05:14:48 AM »
    Hi all!

    I was wondering if it's possible - and if so, how? - to print only a certain part of a text file with the type command.

    e.g:

    Text file:
    Quote

    llama
    A llama is an animal, which is...

    chocolate
    A delicious food which...


    coffee
    A drink which helps keep....

    How would i go about printing only say, the bit
    Quote
    chocolate
    A delicious food which...
    ?


    Thanks in advance,

    Kamak

    Jacob



      Hopeful

      Thanked: 1
      • Experience: Expert
      • OS: Windows XP
      Re: Only typing certain parts of a text file
      « Reply #1 on: June 12, 2008, 10:25:45 AM »
      i also would like to know this.
      sorry I'm of no help.

      .bat_man

      • Guest
      Re: Only typing certain parts of a text file
      « Reply #2 on: June 12, 2008, 10:50:53 AM »
      u cant us the type command alone to generate such an output
      put u can type out som lines of the file

      @echo off
      setlocal ENABLEDELAYEDEXPANSION
      set /a cont=1
      for /f "delims=" %%i in (file.txt) do (
      if "!count!" EQU "3" echo %%i
      set /a count=!count!+1
      )
      endlocal


      this code will print the 3rd line
      if u want it to print from the 3 to 5 row u have to do this


      @echo off
      setlocal ENABLEDELAYEDEXPANSION
      set /a count=1
      set /a count2=3
      for /f "delims=" %%i in (New.txt) do (
      if "!count2!" GTR "5" set /a count2=0
      if "!count!" EQU "!count2!" (
      echo %%i
      set /a count2=!count2!+1
      )
      set /a count=!count!+1
      )
      endlocal
      pause

      Jacob



        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Re: Only typing certain parts of a text file
        « Reply #3 on: June 12, 2008, 11:45:48 AM »
        u cant us the type command alone to generate such an output
        put u can type out som lines of the file

        @echo off
        setlocal ENABLEDELAYEDEXPANSION
        set /a cont=1
        for /f "delims=" %%i in (file.txt) do (
        if "!count!" EQU "3" echo %%i
        set /a count=!count!+1
        )
        endlocal


        this code will print the 3rd line
        if u want it to print from the 3 to 5 row u have to do this


        @echo off
        setlocal ENABLEDELAYEDEXPANSION
        set /a count=1
        set /a count2=3
        for /f "delims=" %%i in (New.txt) do (
        if "!count2!" GTR "5" set /a count2=0
        if "!count!" EQU "!count2!" (
        echo %%i
        set /a count2=!count2!+1
        )
        set /a count=!count!+1
        )
        endlocal
        pause
        Thank You :)

        .bat_man

        • Guest
        Re: Only typing certain parts of a text file
        « Reply #4 on: June 12, 2008, 02:15:08 PM »
        welcom welcom

        Rook



          Starter

          Re: Only typing certain parts of a text file
          « Reply #5 on: August 11, 2008, 12:07:25 PM »
          What if you wanted only certain lines.  Say lines 3, 5, 8, etc.?

          Rook



            Starter

            Re: Only typing certain parts of a text file
            « Reply #6 on: August 11, 2008, 01:33:05 PM »
            Think I got it.  At least it is doing what I want.  Anyone have a cleaner way to do this, post for all to enjoy.

            if exist File2 del file2
            setlocal ENABLEDELAYEDEXPANSION
            set count=0
            for /f %%v in (File1) do (
               set /a count=!count!+1
               echo !count!
                    if !count!==3 echo %%v > File2
                    if !count!==5 echo %%v >> File2
                    if !count!==10 echo %%v >> File2
                    if !count!==70 echo %%v >> File2
                    if !count!==71 echo %%v >> File2
                    if !count!==72 echo %%v >> File2
               )