On Fri, Nov 28, 2014 at 1:51 PM, Baskar Selvaraj <bas...@linuxpert.in> wrote:
[...] > Now, I want only the previous directory, leaving out the last directory. The NF variable in Awk represents the Number of fields that you have got in your current record line. So when you say `print $(NF - 1), $NF` you are printing the (No. Of Fields - 1)th and the (No. Of Fields)th record. So in order to just print the last but one field, you'll just have to print $(NF - 1) and remove the $NF. So your command becomes subject=$(echo $PWD | awk '{print $(NF - 1)}' FS='/' OFS='/') If you are spending quite a bit of time doing things like this, I would recommend spending a while to learn tools like sed and awk. They will be extremely useful. Here[1] is one resource to get you started. [...] -- [1]: http://www.tldp.org/LDP/abs/html/sedawk.html _______________________________________________ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc ILUGC Mailing List Guidelines: http://ilugc.in/mailinglist-guidelines