- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: get lines with digit(s) at the end from a file...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-05-2011 05:14 AM
тАО12-05-2011 05:14 AM
hello,
- field separator can be variabel like "|" or ";"
i want to get lines , which have digits (1-N) at the end , delimited by field separator .
like :
.............;01234
file:
|||||||||||||||||||||||
host1|192.31.41.18|192.30.41.18|20111231|20051001|20141231|||131
host2|192.31.41.17|192.30.41.17|20111231|20051001|20141231|||132
|||||||||||||||||||||||
host3|192.31.41.19|192.30.41.19|20111231|20051001|20141231||||
test:
SFS="|" # <- field separator
grep "${SFS}[0-9][0-9]*$" file
i use infos from this thread:
get the last digit(s) from a line or file
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-05-2011 08:10 AM
тАО12-05-2011 08:10 AM
Re: get lines with digit(s) at the end from a file ( delimited by field separator )
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-05-2011 09:11 AM
тАО12-05-2011 09:11 AM
Re: get lines with digit(s) at the end from a file (delimited by field separator)
>I want to get lines, which have digits (1-N) at the end, delimited by field separator.
grep "${SFS}[0-9][0-9]*$" file
If the separator is only ";" and "|", change to:
grep "[;|][0-9][0-9]*$" file
If it is in a variable, what's wrong with what you had?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2011 01:07 AM
тАО12-07-2011 01:07 AM
Re: get lines with digit(s) at the end from a file ( delimited by field separator )
perl -ne'm/[;|][0-9]+$/ and print' file
i change it to
SFS="|" perl -ne'm/[;$ENV{SFS}][0-9]+$/ and print' file
and it works !
last question :
how can i check , if in field 4 are only digits ( it is a date format with YYYYMMDD)
example:
host1|192.31.41.18|192.30.41.18|20111231|20051001|20141231|||131
it should report : in line N field 4 are characters <> digits
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2011 01:51 AM
тАО12-07-2011 01:51 AM
Re: get lines with digit(s) at the end from a file ( delimited by field separator )
$ perl -aF"\Q$SFS" -nle'$F[3]=~m/^[0-9]{4}/ or print"Field 4 is wrong in line $."' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2011 07:13 AM
тАО12-07-2011 07:13 AM
Re: get lines with digit(s) at the end from a file ( delimited by field separator )
hello,
i tested with
SFS="|"
perl -aF"\Q$SFS" -nle'$F[3]=~m/^[0-9]{4}/ or print"Field 4 is wrong in line $."' file
and for every line i get "Field 4 is wrong"
i add testfile
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2011 08:35 AM - edited тАО12-07-2011 08:49 AM
тАО12-07-2011 08:35 AM - edited тАО12-07-2011 08:49 AM
SolutionSorry. \Q doesn't seem to work in command line option :(
I don't know if that is a bug.
A workaround could be
perl -aF"[$SFS]" -nle'$F[3]=~m/^[0-9]{4}/ or print"Field 4 is wrong in line $."' test.txt
note the brackets around the $SFS. Now every character in $SFS will be a valid field separator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-12-2011 06:32 AM
тАО12-12-2011 06:32 AM
Re: get lines with digit(s) at the end from a file ( delimited by field separator )
perfect, thx