• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Fetch the last value from the file which contains single line

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

I have the below data in one file:

-rw-rw-rw-   1 user     group        7512 Jul  6 16:39 DataWarehouse37_FE_USA_M_20160706_delete.txt

I would like to get the last value like: DataWarehouse37_FE_USA_M_20160706_delete.txt
from the above line through regexp.

I tried using with ([^_]*[^.]*)$ but the output I am getting is only     delete.txt
but I want to retrieve the last word like : DataWarehouse37_FE_USA_M_20160706_delete.txt

Please help me to get the last word/value from the line.

Thanks in adavance
 
author & internet detective
Posts: 39341
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about how you would describe this without a regular expression? Is it all the characters after the last whitespace? Is it the 7th column? Is it the 7th column to the end?
 
Ranch Hand
Posts: 352
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I agree that column parsing (awk) would be better.

Anyway, this is a simple RE:



 
Krish Yeruva
Ranch Hand
Posts: 60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Morris and Boyarsky,

Thanks for your response,

I have used the below regexp to get the last word/value from the single line file in AntScript:

<propertyregex property="FTPFileName" input="@{line}" regexp="([^\s]*)$" select="\1" />

And it is working fine.

Thanks for your support.


 
Jeanne Boyarsky
author & internet detective
Posts: 39341
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! Thanks for sharing it!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!