• 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

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: 39956
804
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: 356
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: 39956
804
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! Thanks for sharing it!
 
Evildoers! Eat my justice! And this tiny ad's justice too!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic