• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read .txt file n append lines using shell script

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
There is a multiple directories which had bunch of files (.txt), where I would like to read the (.txt) file n append some lines on each file using shell script.
Could you pls guide me how to do this n provide the sample script.
Thanks in advance.
Cheers
Jowsaki
 
Pranav Butala
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What platform r u working on? Tried using VBScript to append to a .txt file?
I have a VBScript that reads a .txt file in to an array to perform some calculations. I can modify it append to a .txt file. Let me know if you need it.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pranav Butala:
What platform r u working on? Tried using VBScript to append to a .txt file?

As this is the Linux/UNIX forum, the poster is lucky enough not to have VBScript available.
Sham:
This puts a line of text into a file, destroying any previous contents:
echo "Here is a line of text" > afile.txt
This, on the other hand, appends to an existing file:
echo "Here is another line of text" >> afile.txt
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want something like this...

Anyway, that's a start...it's basic stuff but bash scripting took me a while to get the hang of (mostly because I learned programming on languages with passably decent syntax..."for i in `seq 1 10`" is barbaric eh?...ok maybe that's just an excuse ), so it might save you some time...
Cheers,
--Tim
[ April 13, 2004: Message edited by: Tim West ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic