File Extraction

Hi,

I have three files as below:

AA.DAT20110505063903.Z
AA.DAT20110405062903.Z
AA.DAT20110305061903.Z

All the above files are appended with Date and timestamp in compressed format.

I need to extract AA.DAT20110505063903.Z(which is the latest file) from one server and uncompress it to AA.DAT before FTP'ing to different server.

Please let me know how to perform this using Script.

Thanks in advance
Sue

A=$(ls -1 AA.DAT*.Z| sort -k 1.7,1.14n| tail -1); compress -d $A; mv ${A%.*} $(echo $A| cut -c1-6)

Hi,

When i executed this command, i am getting last file instead of first file. Please help me out.

Thanks
Sue

---------- Post updated 05-06-11 at 02:17 AM ---------- Previous update was 05-05-11 at 08:40 AM ----------

Hi,

I could get the desired file by changing the code to

ls -1 .AADAT*.Z| tail -1

But when i am trying to execute the entire command

A = (ls -1 AA.DAT*.Z| tail -1); uncompress -d $A; mv ${A%.*} $(echo $A| cut -c1-6) i am getting  syntax error: `(' unexpected

Please assist me how to keep this in a script.

Note: Since I am a novice to scripting, I am really facing tough time to get used it.

Thanks
Sue