Sunday, 15 April 2012

sed - Auto file names using awk -


I have a file named "FAI_4O57A", which has always three letters which are underscores and variable length digits from 1-7

I want to remove the first four characters and instead of my own number like 0000001 to 00001, I want to replace the second digit and so on. (For file names automatically number.).

How to use it awk Or sed will appreciate any kind of gratitude. Thank you.

Try doing this:

  rename -n '$ C ++; S / ^ (. {4}) * / Sprintf ("% s% 05d", $ 1, $ c) / e '[ag]] [aged] [ez] _ *   

you change the name of the test ,

See when your tests are OK ( dry run mode) to delete the -n switch).

ex: $ ls -1 DEF_FAI_4O58A FAI_4O57A FTH_4O59A box.py index.html robots.txt test.html $ Rename -n '$ c ++; S / ^ (. {4}) / Sprintf ("% s% 04d", $ 1, $ c) / E '[A-Z] [A-Z] [A-Z] _ * DEF_FAI_4O58A - & gt; DEF_0001 FAI_4O57A - & gt; FAI_0002 FTH_4O59A - & gt; If you really want to do this:

  printf '% s \ n' [AGED] [AGED] [AGED] _ [FTH_0003]   

* | Awk '{c ++; Edit : / P>

If you need to treat columns in YOUR_OWN_FILE :

  rename -n '$ c ++; S / ^ (. {4}) * / Sprintf ("% s% 04d", $ 1, $ c) / E '$ (awk' {print $ 2} 'YOUR_OWN_FILE)    

No comments:

Post a Comment