- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to find a delimiter and delete the next Cha...
Operating System - HP-UX
1753587
Members
6605
Online
108796
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО10-21-2010 03:57 AM
тАО10-21-2010 03:57 AM
Hi,
Please, May I request a help to fix the below?
=============================================
I have a file in one of my HP-UX boxes. This has more than 10000 lines. In each line I need to find out the last appearnce of a delimiter and delete the immediate next character to that delimiter. The delimiter is ├П and the immedeate character is either Y or N.
=============================================
Please help.
Please, May I request a help to fix the below?
=============================================
I have a file in one of my HP-UX boxes. This has more than 10000 lines. In each line I need to find out the last appearnce of a delimiter and delete the immediate next character to that delimiter. The delimiter is ├П and the immedeate character is either Y or N.
=============================================
Please help.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2010 04:31 AM
тАО10-21-2010 04:31 AM
Solution
Hi:
Given an input file like:
# cat ./myfile
a|b|c|d
e|f|g|h
i|j|k|l|m|n
o|p|q|r|s|t|u|v|w|x|y|z
1|2|3|N
4|5|6|7|Y
# perl -nle '@F=split m{\|};pop @F;print join "|",@F' myfile
a|b|c
e|f|g
i|j|k|l|m
o|p|q|r|s|t|u|v|w|x|y
1|2|3
4|5|6|7
Now, if you only want this performed if the last field is "Y" or "N" you could do:
# perl -nle '@F=split m{\|};pop @F if $F[@F-1]=~/(Y|N)/;print join "|",@F' myfile
From you post, I'm not exactly sure of the delimiter you use. I assumed that it was the pipe character. Change the 'm{\|}' and the 'join "|"' pieces to use the correct delimiter.
Regards!
...JRF...
Given an input file like:
# cat ./myfile
a|b|c|d
e|f|g|h
i|j|k|l|m|n
o|p|q|r|s|t|u|v|w|x|y|z
1|2|3|N
4|5|6|7|Y
# perl -nle '@F=split m{\|};pop @F;print join "|",@F' myfile
a|b|c
e|f|g
i|j|k|l|m
o|p|q|r|s|t|u|v|w|x|y
1|2|3
4|5|6|7
Now, if you only want this performed if the last field is "Y" or "N" you could do:
# perl -nle '@F=split m{\|};pop @F if $F[@F-1]=~/(Y|N)/;print join "|",@F' myfile
From you post, I'm not exactly sure of the delimiter you use. I assumed that it was the pipe character. Change the 'm{\|}' and the 'join "|"' pieces to use the correct delimiter.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2010 05:16 AM
тАО10-21-2010 05:16 AM
Re: Script to find a delimiter and delete the next Character in each line
>> The delimiter is ├Г and the immedeate character is either Y or N.
if there are only ever is a Y or N, then you can blindly delete the last char.. but that get's rid of the 'z' in Jim's example
# perl -pe 's/(.*├Г )./$1/'
If it must be a Y or N, and at the very end, then you can tighten up with:
# perl -pe 's/(.*├Г )[YN]$/$1/' tmp.txt
If there ever any text following the Y or N, then that needs to be remembered also. and you could use:
# perl -pe 's/(.*├Г )[YN]([^├Г ]*)$/$1$2/' tmp.txt
That last most difficult regexp breaks down to:
(.*├Г ) = match and remember in $1 any repeations(*) of any character (.) up to and including the last ├Г . 'Aggresive' wildcard.
[YN] = a Y or a N, add y and n as needed.
([^├Г ]*)$ = match and remember in $2 any series of non-├Г characters which must be at the end of the line.
Provide a few concrete, and most tricky, input and output lines in a TEXT attachment if more help is needed.
Good luck,
Hein.
if there are only ever is a Y or N, then you can blindly delete the last char.. but that get's rid of the 'z' in Jim's example
# perl -pe 's/(.*├Г )./$1/'
If it must be a Y or N, and at the very end, then you can tighten up with:
# perl -pe 's/(.*├Г )[YN]$/$1/' tmp.txt
If there ever any text following the Y or N, then that needs to be remembered also. and you could use:
# perl -pe 's/(.*├Г )[YN]([^├Г ]*)$/$1$2/' tmp.txt
That last most difficult regexp breaks down to:
(.*├Г ) = match and remember in $1 any repeations(*) of any character (.) up to and including the last ├Г . 'Aggresive' wildcard.
[YN] = a Y or a N, add y and n as needed.
([^├Г ]*)$ = match and remember in $2 any series of non-├Г characters which must be at the end of the line.
Provide a few concrete, and most tricky, input and output lines in a TEXT attachment if more help is needed.
Good luck,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2010 08:27 AM
тАО10-21-2010 08:27 AM
Re: Script to find a delimiter and delete the next Character in each line
Many thanks for your quick response.
The delimiter is ├Г (Upper case I with two dots on the top). I will try as per your suggestions and let you know the results shortly.
The delimiter is ├Г (Upper case I with two dots on the top). I will try as per your suggestions and let you know the results shortly.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP