anyone does any linux scripting?

Discussion in 'OT Technology' started by Jericho, Oct 18, 2004.

  1. Jericho

    Jericho Active Member

    Joined:
    Oct 21, 2002
    Messages:
    34,140
    Likes Received:
    0
    anyone here does any minor linux scripting, I need a script that runs through every file in a directory with a specific extension .abc for example and adds a line to the beginning, anyone know how?
     
  2. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,454
    Likes Received:
    12
    A lot of files? Add a single line? The same line every time?

    Here's the dumbest way to do it.

    #!/bin/ksh

    echo "A line that you want to add to the beginning of each file\nmore lines if you want to" >> first_line.txt
    for i in `ls *.abc`
    do
    cat first_line.txt $i > $i.tmp
    mv $i.tmp $i
    done
     
  3. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    :coold: I would have done it in TCL, but pretty much the same algorithm.
     
  4. Jericho

    Jericho Active Member

    Joined:
    Oct 21, 2002
    Messages:
    34,140
    Likes Received:
    0
    thanks

    :coold:
     

Share This Page