Shell script to read a .DAT file & rename it

Discussion in 'HOWTO-Related Questions' started by yadavmanoj78, Mar 11, 2014.

  1. yadavmanoj78

    yadavmanoj78 New Member

    I need a batch script which can read a file *.D00000.DAT and find the specific line as below

    *-*-* Job: 11676 Name: ABCDEFGH User: mfuser Date: 03/13/13 Time: 10:47:46 *-*-*

    and store Job, Name, Date & Time in different variables.

    Then do the following:

    1. close the file.
    2. Rename: keep the original file name & add the "Name" into it. Like below:

    ABC2013.C0000.D133136.J11341.D00000.DAT after renaming it should be ABCDEFGH.ABC2013.C0000.D133136.J11341.D00000.DAT

    3. Look for other files which has same Job and add the Name in that file name as well. Like below:

    ABC2013.C0000.D133136.J11341.D00001.SYSPRINT.DAT will look like ABCDEFGH.ABC2013.C0000.D133136.J11341.D00001.SYSPRINT.DAT

    3. Create a folder and name it with Name-Job-Date-Time
    3. Move the renamed file into the folder
    4. repeat the process for next *.D00000.DAT file
  2. srijan

    srijan New Member HowtoForge Supporter


    I am assuming that you are on linux with bash terminal.
    This can be done as follows:
    for a single file. The same can be done for other files with a loop function.

    It will be easy to create the full script if you provide afew sample *.DAT file


Share This Page