topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 7:57 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: anyone know a commandline tool to add a line of text to end of a text file?  (Read 18748 times)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
anyone know a commandline tool to add a line of text to end of a text file?
e.g.
addlinetofile.exe "c:\notes.txt" "this is a line of text to add"

i could code this easily enough and it would probably be 2 lines of perl but i wonder if anyone knows any existing tools to do this, maybe with some extra functionality?

dajo

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 32
    • View Profile
    • Donate to Member
how about

echo "this is a line of text to add" >> c:\notes.txt

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
thanks dajo, i'm always overlooking the simplest solutions :)

but still i can't help but wonder if there are some existing tools that offer some more functionality i might not have even thought of yet..

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
a few Text manipulation tools i know (and try to use):

* DOS (like dajo's)
* sed
* awk

*
Title   : FILTER
Version : 4.0
Date    : Mar 24,2000
Author  : J.R. Ferguson, Amsterdam, The Netherlands
Download: http://hello.to/ferguson (DOS Filters)


Usage : FILTER [[<]in] [>out] [/option[...]] [...]] [txtopt [...]]

option: C[n,s,d]   Copy n characters from position s to d.
        D[n,p]     Delete n characters at position p.
        E[+/-][n]  Expand tabs (
  • ) or replace spacegroups by tabs (-),

                   where n [8] is tab field length.
        F[n,m]     Fill nonblank lines with dots to width n [70],
                   skipping first m
  • lines. Implies /T.

        H          Send this help text to (redirected) output.
        ?          Send this help text to screen (page by page)
        I[n,p]     Insert n spaces at position p.
        J[+/-]     Add/remove Carriage Return before Line Feed
  • .

        L[+/-]     Add/remove Line Feed after Carriage Return
  • .

        M[n,s,d]   Move n characters from position s to d.
        N[n]       Number lines, use n [4] digits,
        O[n,s,d]   Overwrite n chars from position s to d.
        P          Reset parity bit. Implied by /W.
        R[n]       Remove n trailing lines after processing /S and /X.
        S[n,m]     Skip m lines starting at line n.
        T          Trim trailing blanks. Implied by /F.
        U[+/-]     Convert to upper/lower case
  • .

        V[n,s]     Reverse n [all] characters starting at position s.
        W          Wordstar document ==> ASCII textfile. Implies /P.
        X[n,m]     Extract m lines starting at line n.
        Z
  •        Remove NULLs. Z+: also ANSI screen control sequences.


txtopt: /A[+/-][p]
  • text   Include lines after  specified text only.

        /B[+/-][p]
  • text   Include lines before specified text only.

        /G[+/-][p]
  • text   Include lines with the specified text only.

*
FU - Text Filter Utility.  A multi-purpose text line filter.

        Version 3.56  (C) Copyright 1990 by David Lo.  Jun/90

Usage
        -----
        FU :option parameters ...

        where :options is one or more from the following list.  Options
        below are grouped by function.  Parameters in square brackets are
        optional.  A brief description of the option is shown.  Use FU -? or
        FU with no parameters for a list of the options.

        Select lines:
          BEGSTR str [n]               lines after a line with search string
          COPY                         all lines
          DEROFF [str]                 lines without .nroff commands
          ENDSTR str [n]               lines before a line with srch string
          FIND str                     lines containing a string
          FIND0 str                    lines not containing a string
          LINES [first [last]          lines in given line range
          NULL0                        non-blank lines
          OUTSTR str1 str2 [n]         lines outside str1 and str2
          SURSTR str1 str2 [n]         lines between str1 and str2
          UNIQUE                    non-repeating lines in sorted file

        Remap characters:
          ASCII                        zero high-bit
          DEBOX [box_str]              remap box chars to printable chars
          ENC [keyword]                encrypt/decrypt
          LOWER                        convert to lower case
          TRANS old [new]              translate one set of chars to another
          UPPER                        convert to upper case

        Change lines:
          CHANGE old [new]             change one string to another
          DECTRL [HLD]*                delete/change 0..31/128.255 to \nnn
          NUM [n_digits [spaces]]      number lines
          PRINTF [n]                   convert \nnn to characters
          PREFIX str                   add string before line
          SUFFIX str                   add string after line

..... and much more



*
LM  version 2.06 

   The LM command inputs line by line from files or stdin, then
   manipulate the line according to the command line options before
   sending the final form to a file or stdout.

   The main operations supported are grip/non-grip, search/replace,
   synchronised line appendage from other files, input/output line
   selection by line numbers or passwords, spaces/empty lines
   absorption, filewise update or renaming, line width imposition and
   etc. Command line options may be read in from a text file, and input
   lines can also be taken from the command line aline.

 AUTHOR: ¦
 +---------+

   Zhuhan JIANG, University of New England, Armidale NSW 2351, Australia


Line manipulator  - ver 2.06 January 1997  by Zhuhan Jiang.

usage     lm  [-options] [string1] [string2 etc]
helps     lm  -h (simple help)  lm -H (more help)  lm -hH (manual)

priority  -@ -<* -;* -hH -j# -v -V -X# -/# -{#[]}* -BE*(#) -zZ# -$*(j20-28&#)
          -c# -:* -^*(+1) -fF*(+0**X7-11) -*`* -pP*(M#+2) -iI# -lL# -sS#
          -dD*(C2n#) -g*(G#J1j9!#)[X5] -qr*(j1j2j6-8) -QR*(j3j4j6-8) -()*
          -m*(C3kK*) -Y# -t# -T# -a -A* -~*(C1J2) -=#(X1) -y# -oO#(N#!#) -!#
          -N# -be*(#) -w#(W#) -uU*(+3) -#? -#?(even no. such options) -.# -x#
          *=str, #|?=no. (after a char), ()=related mode, []=forced option
shorthand //# via -f^uU< is #th file of LMFILES, -F//*[;|:]* parses path *
tmpfiles  in TMPDIR or root directory
extendkey (dos) 0? for -$* under -j28 is denoted by 255? e.g. "-/255$;"=F1



*
Minitrue  Version 2.0.2

http://www.pagesz.net/~minitrue
 Copyright (C) 1995-99 Andrew B. Pipkin

MiniTrue 2.0.2 (Alpha #3) for 16-bit DOS  Dec 20 1999
Copyright (C) 1995-99 Andrew Pipkin 
MiniTrue is free software released with no warranty. See COPYING for details.

Usage: mt [-options] [files] - [strings]

-a  search All files                 -b  make Backup files
-c  Case insensitivity               -d  preserve original Datestamps
-e  ignore file Errors               -f  Fold lines at word breaks
-h  begin in Hex mode                -i:FILE read strings from FILE
-k  Keep statistics                  -l  generate Log file
-mNUM set top Margin                 -n  No prompting
-o  use standard Output (grep mode)  -p:SET define set of printing chars
-q  Quiet mode                       -r  Recurse through subdirectories
-s  accelerated Scrolling            -tTABSIZE set Tab size
-u  set region for boolean searches  -v  set Video mode
-w  Whole words only                 -x  use regular eXpressions
-y  skip binarY files                -z  unZip files before searching
-@:FILE read filenames from FILE

Default options: -c -x -z-:.zip:pkunzip:-c -p:[\x20-\x7e\xa0-\xff] -b:* -s6:10

Enter mt -? to view the help file, mt -?:<option> for option information


want to know about more tools too.


-----
couldn'd this posting input window be bigger sized ???
e.g. expanded to the left and double in high.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
cool links, thanks stefan :)

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,205
    • View Profile
    • Donate to Member
Unix  cat  in various ports to Windows/DOS

Carol Haynes

  • Waffles for England (patent pending)
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 8,069
    • View Profile
    • Donate to Member
How about good old edlin (built in to DOS and WinXP Command Windows)

See Edlin Command Help

There is also mouse driven DOS command Edit

dajo

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 32
    • View Profile
    • Donate to Member
Stefan mentioned SED and AWK, which are both command-line text manipulation tools.  SED is the simplest, and is best used for regular expression search and replace.  AWK is its own little programming language, and is a more powerful than SED, but much lighter than Perl.

I spent a lot of time exploring text manipulation tools a few years back.  I ended up using AWK and Perl for most things, but then I found Datamystic's TextPipe Pro (shareware, $299) http://snipurl.com/leapfrog_textpipe, for it's power and ease of use.  I became such a fan of the product that I have since become a reseller.

I might be able to work out a discount deal on TextPipe for DonationCoder members only... Mouser, I will contact you about this offline.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
textpipe really looks like a great application; probably even with a real discount it would be out of range for most of us but still any discount for our members would be welcome, and you might just make someone's day :)  :up:

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,205
    • View Profile
    • Donate to Member
Stefan mentioned SED and AWK, which are both command-line text manipulation tools.  SED is the simplest, and is best used for regular expression search and replace.  AWK is its own little programming language, and is a more powerful than SED, but much

Uh, I ended up feeling that SED was a bit like trying to use an early programmable calculator, and that AWK was actually easier simply because it's more like a recognisable language.  Eric Pement has a good Web site for both and also for the kind of command line tools Stefan mentioned (go to his SED page and keep paging down);

Eric Pement's  Web site; SED, Awk, Perl, search-and-replace utilities including useful supplementary information, help and workarounds for Minitrue / MT / MTR / Ministry of Truth under Windows 2000 / Win2K.

http://www.student.n...du/pemente/index.htm

One set of Unix utils ported to Windows and including CAT is at
http://unxutils.sourceforge.net

Mouser, here's the online help for the Berkley utils version of cat, more informative than the GNU equivalent;

=== begin quote ===
usage: berkcat file(s)
Concatenates the file(s) to the standard output.
If one of the files is `-', the standard input is used.
No options.
Example:
       C:>cat - file1 >newfile
       this is the new first line
       and this is the second.
       ^Z
       C:>mv newfile file1

This is a way to add 2 lines to the beginning of file1 without using
an editor.

To append file1 at the end of file2, type
        cat file1 >> file2
=== end quote ===






AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Thanks rjbull,
that's very helpfully.

I played around a bit (i like unix tools but i have mostly plain dos commends only):

>To append file1 at the end of file2, type
>        cat file1 >> file2
C:\>type file1 >>file2

To append a line of text at the end of file2, type
C:\>echo "some text" >>file2

To append a line of text at the beginn of file3, type
C:\>echo "some text" >tmpfile && type file3 >> tmpfile && ren tmpfile file3


kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
    • View Profile
    • Donate to Member
Is it possible to append text to a file without recreating the file? I am just afraid that that would change creation modification dates of the file, and that info is much needed for the file I am working with.


f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
kartal: if you use something like "echo blah >> file.txt", the last-modified will be changed, creation date shouldn't... also, not all tools will be good for this, I'm afraid SED and AWK would read in the entire existing file before appending the line? Bad if you're dealing with huge files :)
- carpe noctem

kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
    • View Profile
    • Donate to Member
I do not have any problem with modification date. But I hate to see that creation date has changed.

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
i think i wrote a tiny exe to do this called "addnote" which i include with FARR..

kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
    • View Profile
    • Donate to Member
amazing! thanks Mouser

kartal

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 1,529
    • View Profile
    • Donate to Member
It works amazing. But I am wondering if it is possible to remove formatting or change the formatting in the code?

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
I was looking for text manipulation software and found this link

It's a lot of free mainly stuff and with programs like

http://www.sac.sk/files.php?d=16&l=I

   INI v1.01 - Util to provide access to INI-files from the command line

May be useful.

I continue

Aritech INi File Editor