![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 14:21 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » How to add a line at the beginning of a text file |
| Printable Version 1,639 / 12 |
| Floor1 hgx126 | Posted 2009-01-27 03:00 |
| 初级用户 Posts 80 Credits 100 | |
|
I have several hundred text files, and I want to insert one line at the beginning of each file:
For example, one of my files is: 5471,An Degang,"1,100.00",2000-6-18,2001-4-20,2003-9-21,bad debt,loss,,210.87,4.851E+13,8.81301E+13 5471,An Degang,"9,670.00",1997-10-8,1998-9-20,2003-9-21,bad debt,loss,,4659.83,4.851E+13,8.81301E+13 5471,An Degang,"3,120.00",1998-9-23,1999-9-20,2003-9-21,bad debt,loss,,598.11,4.851E+13,8.81301E+13 …… I want to insert this line at the beginning: Institution,Account Name,Balance,Loan Date,Due Date,Interest Start Date,Level 4,Level 5,On-balance Interest,Off-balance Interest,Customer No.,IOU No. How should I write the code? Using sed is fine too. I've searched online for a long time and still couldn't find suitable code. Please help! |
|
| Floor2 wxcute | Posted 2009-01-27 11:04 |
| 中级用户 Posts 211 Credits 458 | |
| Floor3 hgx126 | Posted 2009-01-28 00:05 |
| 初级用户 Posts 80 Credits 100 | |
|
Thanks, brother wxcute.
If I only want to add that line to the original file itself, instead of generating another file with "new_" plus the original filename, how should I write the code? |
|
| Floor4 zzhh612 | Posted 2009-01-28 00:14 |
| 中级用户 Posts 103 Credits 278 | |
|
Generate another file with "new_" plus the original filename, then change it back to the original filename, and doesn't that become
the original file? As long as it achieves the goal, that's fine, don't be so rigid about it. If you really can't stand the old one, just delete it. |
|
| Floor5 hgx126 | Posted 2009-01-28 00:26 |
| 初级用户 Posts 80 Credits 100 | |
| Floor6 wxcute | Posted 2009-01-28 11:53 |
| 中级用户 Posts 211 Credits 458 | |
|
That works too, just remove the “new_” string.
|
|
| Floor7 ceii | Posted 2009-01-28 19:33 |
| 初级用户 Posts 45 Credits 115 | |
|
[ Last edited by ceii on 2009-1-28 at 19:35 ] |
|
| Floor8 motop | Posted 2009-01-29 13:35 |
| 初级用户 Posts 40 Credits 56 | |
|
Good, very practical.
|
|
| Floor9 hgx126 | Posted 2009-01-31 02:12 |
| 初级用户 Posts 80 Credits 100 | |
| Floor10 ceii | Posted 2009-02-01 10:47 |
| 初级用户 Posts 45 Credits 115 | |
|
This is a version issue.
I'm using GNU sed version 4.0.7 |
|
| Floor11 zhengqian529 | Posted 2009-02-01 12:02 |
| 初级用户 Posts 93 Credits 100 From 湖南 | |
|
Post #2 is pretty good.
But there's one drawback: if the original TXT file contains "branch, account name, balance, loan date, maturity date, interest start date, category four, category five, on-balance-sheet interest, off-balance-sheet interest, customer number, IOU number", and also has other content. set/p fh=<"%%i" if not "!fh!"=="%head%" copy/b head.ini+"%%i" "new_%%i" Should some other check be added as well? |
|
| Floor12 samliu | Posted 2009-02-05 21:58 |
| 新手上路 Posts 15 Credits 15 | |
|
Oh, so it can be done like this too.
Learned something. |
|
| Floor13 bobofu | Posted 2009-07-13 07:00 |
| 新手上路 Posts 8 Credits 13 | |
|
@echo institution,account name,balance,loan date,maturity date,interest start date,4th category,5th category,on-balance-sheet interest,off-balance-sheet interest,customer number,loan note number >>header.txt
copy/b header.txt+detal.txt del detal.txt ren header.txt detal.txt |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |