I'm running into a slight quandary with this particular script I need. I have a used egrep to yank from a large number of config files the location parameter of various unity databases. I have that information in a script. For example, the data looks like:


So, the problem is each location doesn't have a particular field I can cut with "/" as the delimiter, however, the second to last field in that string is what I want: demo and ss. Is there an easy way to script this. I want to basically spin through this flat file (290 lines), in a new file print out the complete path and then on the same line separated by a space the second to last field.

The end result would look like:

/home/test/demo/new demo
/home/test/demo/old demo
/home/yikes/mydir/ss/new ss
/home/yikes/mydir/ss/old ss

Thanks for the help!

asked 20 Sep '10, 01:28

Andy's gravatar image

accept rate: 14%

cat $FILE | awk -F'/' '{print $0, $(NF-1)}'


answered 20 Sep '10, 08:09

Bob%202's gravatar image

Bob 2
accept rate: 100%

Great! Thanks for your help!

(20 Sep '10, 15:04) Andy
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 20 Sep '10, 01:28

Seen: 4,926 times

Last updated: 20 Sep '10, 08:09

powered by OSQA