-3

I want a simple way to add the same text (e.g. "bye" or more lines) to a group of files using a small script. I tried something with ed and vi inside of a script, but it did'nt work.

Edit: I edit this coment to be more specific:

I have the files c0001.gin c0002.gin ... up to let's say 500. I need to add to the end of each file the next text:

species
Ca    core  2.00000000
Co    core  2.00000000
C     core  1.34353898
O     core  1.01848700
O     shel -2.13300000
buck intra
O     core O     core  4030.3000     0.245497 0.00000000      0.00  2.50 1 0 0
buck
Ca    core O     shel  2154.0600     0.289118 0.00000000      0.00 10.00 1 0 0
Co    core O     shel  1095.6000     0.286300 0.00000000      0.00 10.00 1 0 0
Ca    core C     core 120000000.000  0.120000 0.00000000      0.00 10.00 1 0 0
Co    core C     core  95757575.760  0.120000 0.00000000      0.00 10.00 1 0 0
buck inter
O     shel O     shel  64242.454     0.198913  21.843570      0.00 15.00 1 0 0
morse intra bond
C     core O     core 5.0000000     2.5228      1.19820  0.0000 1 0
three
C     core O     core O     core 1.7995     120.00
outofplane bond intra
C     cor O     cor O     cor O     cor 8.6892 360.0
spring
O      52.740087

I want just a script to do that.

Furthermore, the files are in folder called "CALCS" and I wanted to move each file to another folder inside CALCS called "001" for c0001.gin, "002" for file c0002.gin and so on.

Thanks in advance

git
  • 151
  • 9
  • Something like `for file in ; do echo "" >> "${file}" ; done`. – Biffen Oct 09 '15 at 07:46
  • @Biffen Some error happen with this. – git Oct 09 '15 at 07:53
  • 1
    Oh, ‘*some error*’, eh? Well, use *some* solution. – Biffen Oct 09 '15 at 07:54
  • @Biffen -bash: syntax error near unexpected token `<'. Sorry for my english, not everyone speak english fluently. – git Oct 09 '15 at 07:57
  • 1
    `` and `` are meant to be replaced. Since you've not told us to *which* files you want to write you'll have to do that bit yourself. – Biffen Oct 09 '15 at 07:59
  • So, as @Biffen says, if you want to add the words "grey tails" to all files whose names begin with "elephant"... `for f in elephant*; do echo "grey tails" >> "$f" ; done` – Mark Setchell Oct 09 '15 at 08:06
  • Right!! I'll try this. Thank you very much. – git Oct 09 '15 at 08:07
  • 3
    Visualize @Biffen slowly turned toward the wall softly banging his head against said wall... ... – David C. Rankin Oct 09 '15 at 08:12
  • 1
    git - this whole swarm of confusion is caused by the failure to provide a concise example of your code which we here can verify and make suggestions from. We all suffer from the same limitations -- we cannot see what is on your screen... That's where you have to help us – David C. Rankin Oct 09 '15 at 08:14
  • @DavidC.Rankin Desk. And not that softly. Glad someone understands. – Biffen Oct 09 '15 at 08:16
  • Ok I´ll edit. Thanks – git Oct 09 '15 at 08:23

1 Answers1

1
#!/bin/sh

text="${1:?Usage: $0 <text> <file>...}"
shift
files="${@}"

for file in $files
do
    echo "$text" >> "$file"
done
Alvaro Gutierrez Perez
  • 3,669
  • 1
  • 16
  • 24