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

Author Topic: Removing all text after a certain line/character  (Read 21551 times)

0 Members and 1 Guest are viewing this topic.

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Removing all text after a certain line/character
« Reply #15 on: June 07, 2007, 08:03:34 AM »
if the file you wanted to edit was a batch file like this:
Code: [Select]
@echo off
echo hello
echo how are you
echo.
pause
and say you wanted to add a "echo i'm good", do this:
Code: [Select]
@echo off
del "C:\path\file.bat"
echo @echo off >>"C:\path\file.bat"
echo echo hello >>"C:\path\file.bat"
echo echo how are you >>"C:\path\file.bat"
echo echo. >>"C:\path\file.bat"
echo echo I'm good >>"C:\path\file.bat"
echo pause >>"C:\path\file.bat"

This would delete the old one and create a new file with the added sentence.
The finished product would be:
Code: [Select]
@echo off
echo hello
echo how are you
echo.
echo I'm good
pause

ghostdog74



    Specialist

    Thanked: 27
    Re: Removing all text after a certain line/character
    « Reply #16 on: June 07, 2007, 08:06:08 AM »
    wow fantastic! but what has this got to do with what OP wants?

    Carbon Dudeoxide

    • Global Moderator

    • Mastermind
    • Thanked: 169
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Experience: Guru
    • OS: Mac OS
    Re: Removing all text after a certain line/character
    « Reply #17 on: June 07, 2007, 08:08:43 AM »
    wow fantastic! but what has this got to do with what OP wants?
    well....he wanted to replace a line of text....
    This is another way to 'replace' something  :P

    ghostdog74



      Specialist

      Thanked: 27
      Re: Removing all text after a certain line/character
      « Reply #18 on: June 07, 2007, 08:37:52 AM »
      wow fantastic! but what has this got to do with what OP wants?
      well....he wanted to replace a line of text....
      This is another way to 'replace' something  :P
      wow and if the input file has 1000000000 lines, are you going to key in a batch file with 1000000000 echo lines ?

      contrex

      • Guest
      Re: Removing all text after a certain line/character
      « Reply #19 on: June 07, 2007, 09:08:09 AM »
      The whole idea of text processing in batch files has now been explained exhaustively in about 6 different ways, and I would have thought that if a person had not "got" it by now, it would be time to find a less taxing hobby.


      GuruGary



        Adviser
        Re: Removing all text after a certain line/character
        « Reply #20 on: June 07, 2007, 11:43:41 PM »
        Is there any command that can alter/manipulate text? If I get that, then I'll start with some easy, like adding a 1 to the end of each file. Like this:

        Before:-

        apples
        pears
        ADD

        After:-

        apples
        pears
        ADD
        bananas
        Adding a line of text to the end of a file is easy.  If your file is named food.txt, then your code would be:
        Code: [Select]
        echo bananas >>food.txt

        Carbon Dudeoxide

        • Global Moderator

        • Mastermind
        • Thanked: 169
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Experience: Guru
        • OS: Mac OS
        Re: Removing all text after a certain line/character
        « Reply #21 on: June 08, 2007, 12:00:43 AM »
        Code: [Select]
        echo bananas >>food.txt
        LOL funny.
        That code puts the text at the end of the file you want to edit.

        Dark Blade

          Topic Starter
        • Forum Gaming Master


        • Adviser

          Thanked: 24
          • Yes
        • Experience: Experienced
        • OS: Windows XP
        Re: Removing all text after a certain line/character
        « Reply #22 on: June 08, 2007, 12:30:32 AM »
        Finally...

        Adding - Can do
        Replacing whole file - Can do (so many echos... :P)
        Deleting

        I just made something that deletes a file if it exists, then add lines to the new file (like what Carbon Dudeoxide did, but it adds the output of my batch file).


        I'm going to start making something that deletes all text after a specified line.