Re: [Ilugc] [HELP] Extracting directory names using sed

2014-12-07 Thread Arun Khan
On Fri, Nov 28, 2014 at 1:08 PM, Baskar Selvaraj wrote: >>> $ echo "/pub/videos/nptel/Computer Science and Engineering/Data >>> Structures And >>> Algorithms" | awk '{print $(NF - 1), $NF}' FS='/' OFS='/' >> >> It works, but however I could not store the output in a variable >> because of long

Re: [Ilugc] [HELP] Extracting directory names using sed

2014-11-28 Thread Shrayas rajagopal
On Fri, Nov 28, 2014 at 1:51 PM, Baskar Selvaraj 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

Re: [Ilugc] [HELP] Extracting directory names using sed

2014-11-28 Thread Baskar Selvaraj
> > Ok now. > > subject=$(echo $PWD | awk '{print $(NF - 1), $NF}' FS='/' OFS='/') No idea with awk, sorry for troubling again. Now, I want only the previous directory, leaving out the last directory. /pub/videos/nptel/Computer Science and Engineering/Data Structures And Algorithms to Computer

Re: [Ilugc] [HELP] Extracting directory names using sed

2014-11-27 Thread Baskar Selvaraj
>> $ echo "/pub/videos/nptel/Computer Science and Engineering/Data Structures >> And >> Algorithms" | awk '{print $(NF - 1), $NF}' FS='/' OFS='/' > > It works, but however I could not store the output in a variable > because of long file name in the output. > > echo $PWD | awk '{print $(NF-1), $

Re: [Ilugc] [HELP] Extracting directory names using sed

2014-11-27 Thread Baskar Selvaraj
On Fri, Nov 28, 2014 at 12:11 PM, Shakthi Kannan wrote: > Hi, > Use awk: > > $ echo "/pub/videos/nptel/Computer Science and Engineering/Data Structures > And > Algorithms" | awk '{print $(NF - 1), $NF}' FS='/' OFS='/' It works, but however I could not store the output in a variable because of

Re: [Ilugc] [HELP] Extracting directory names using sed

2014-11-27 Thread Shakthi Kannan
Hi, --- On Fri, Nov 28, 2014 at 11:58 AM, Baskar Selvaraj wrote: | I need to extract the last two directory names using sed. Any | help/pointers would be appreciated \-- Use awk: $ echo "/pub/videos/nptel/Computer Science and Engineering/Data Structures And Algorithms" | awk '{print $(NF - 1

[Ilugc] [HELP] Extracting directory names using sed

2014-11-27 Thread Baskar Selvaraj
Dear all, I need to extract the last two directory names using sed. Any help/pointers would be appreciated input: /pub/videos/nptel/Computer Science and Engineering/Data Structures And Algorithms output should be: Computer Science and Engineering/Data Structures And Algorithms -- S. Baskar