Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Check first 3 characters of a unix file and rewrite based on the values.  (Read 3529 times)

0 Members and 1 Guest are viewing this topic.

jchappel

  • Guest
I have a requirement to read the first 3 characters of the data inside a file and then rename the file based on the values of that data.

Example:

Read FileA
If data in positions 1 - 3 equal "ITP" then rename file to FileA_ITP, else if data in positions 1 - 3 equal "UNB", then rename file FileA_UNB
Write new filename

I was thinking I could use a GREP command to look at and determine the value of the first three positions of the data inside the file, but I'm not sure if that will work and what command or syntax I need to rewrite the file name from that data.

Appreciate any feedback.