HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Replacing special characters by spaces
Operating System - HP-UX
1826268
Members
3679
Online
109692
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
Forums
Discussions
Discussions
Discussions
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
09-08-2003 08:13 AM
09-08-2003 08:13 AM
Replacing special characters by spaces
I need to do the following with the help of a Korn Shell script:
--My input file has multiple fields containing Cutomer Detail entity information
--I need to examine Customer Name attribute using the following logic:
if the first 3 characters of the CUST_NM field are blanks or underscores, THEN ???IS_VALID_CUST_NAME_F??? attribute is set to 0.
if the first character of the CUST_NM field is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, THEN ???IS_VALID_CUST_NAME_F??? attribute is set to 0.
if the first character of the CUST_NM field is asterisk, THEN ???IS_VALID_CUST_NAME_F??? is set to 0.
IF ???IS_VALID_CUST_NAME_F??? is non-zero, convert any of the following special characters in the CUST_NM field to a space: ???{???, ???}???, ??????, ???$???, ???@???, ???=???, ???,???(comma), ???.???(period), ???`???, ????????? (double quote), ???/???, ???\???, ???|???, ???&???, ???)???, ???#???, ???(???, ???*???, ???!???, ???~???, ???^???, ??? ???, ????????? (single quote).
--Modified Customer Name attribute and IS_VALID_CUST_NAME_F attribute along with other Customer Detail attributes must be written to an output file.
I know I can use awk/sed/tr to accomplish what I need. I am not that much familiar on how to use them. Any help in this regard will be appreciated.
Thanks in Advance
--My input file has multiple fields containing Cutomer Detail entity information
--I need to examine Customer Name attribute using the following logic:
if the first 3 characters of the CUST_NM field are blanks or underscores, THEN ???IS_VALID_CUST_NAME_F??? attribute is set to 0.
if the first character of the CUST_NM field is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, THEN ???IS_VALID_CUST_NAME_F??? attribute is set to 0.
if the first character of the CUST_NM field is asterisk, THEN ???IS_VALID_CUST_NAME_F??? is set to 0.
IF ???IS_VALID_CUST_NAME_F??? is non-zero, convert any of the following special characters in the CUST_NM field to a space: ???{???, ???}???, ??????, ???$???, ???@???, ???=???, ???,???(comma), ???.???(period), ???`???, ????????? (double quote), ???/???, ???\???, ???|???, ???&???, ???)???, ???#???, ???(???, ???*???, ???!???, ???~???, ???^???, ??? ???, ????????? (single quote).
--Modified Customer Name attribute and IS_VALID_CUST_NAME_F attribute along with other Customer Detail attributes must be written to an output file.
I know I can use awk/sed/tr to accomplish what I need. I am not that much familiar on how to use them. Any help in this regard will be appreciated.
Thanks in Advance
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2003 12:56 PM
09-08-2003 12:56 PM
Re: Replacing special characters by spaces
This isn't quite what you want, but it's all I have time for!:
Run this:
# awk -f cust.awk cust.data | sed 's/~/ /'
Where:
cust.awk is:
/^[0-9*]/ { Valid = 0; print $0, Valid }
/^ / { Valid = 0; print $0, Valid }
/^___/ { Valid = 0; print $0, Valid }
/^[A-z]/ { Valid = 1; print $0, Valid }
and, cust.data is:
Customer1 Data1
_Customer2 Data2
3Customer3 Data3
4Custom{r4 Data3
*Custom Vcustomer6 data6
Acustom~r7 Data7
The output is:
# awk -f cust.awk cust.data | sed 's/~/ /'
Customer1 Data1 0
_Customer2 Data2 1
3Customer3 Data3 0
4Custom{r4 Data3 0
*Custom Vcustomer6 data6 1
Acustom r7 Data7 1
Run this:
# awk -f cust.awk cust.data | sed 's/~/ /'
Where:
cust.awk is:
/^[0-9*]/ { Valid = 0; print $0, Valid }
/^ / { Valid = 0; print $0, Valid }
/^___/ { Valid = 0; print $0, Valid }
/^[A-z]/ { Valid = 1; print $0, Valid }
and, cust.data is:
Customer1 Data1
_Customer2 Data2
3Customer3 Data3
4Custom{r4 Data3
*Custom
Acustom~r7 Data7
The output is:
# awk -f cust.awk cust.data | sed 's/~/ /'
Customer1 Data1 0
_Customer2 Data2 1
3Customer3 Data3 0
4Custom{r4 Data3 0
*Custom
Acustom r7 Data7 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2003 02:34 PM
09-08-2003 02:34 PM
Re: Replacing special characters by spaces
In order to help you efficiently, more info is needed.
- What is the delimiter in your datafile ?
- What is the field number of CUST_NM ?
- How many fields are there in total ?
Even better would be a sample record, of course.
If you can get the CUST_NM field to be the first, things will be easier. Otherwise you might have to do a bit of counting..
Let us know
- What is the delimiter in your datafile ?
- What is the field number of CUST_NM ?
- How many fields are there in total ?
Even better would be a sample record, of course.
If you can get the CUST_NM field to be the first, things will be easier. Otherwise you might have to do a bit of counting..
Let us know
an engineer's aim in a discussion is not to persuade, but to clarify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2003 04:10 AM
09-10-2003 04:10 AM
Re: Replacing special characters by spaces
Thanks for your responses. I was able to complete the coding with the help of my co-worker.
I am posting the solution if anyone is interested.
AWK script:
BEGIN { FS = "\t"; OFS = "\t" }
{
if ( $21 ~ /^ / || $21 ~ /^___/ || $21 ~ /^[0-9]/ || $21 ~ /^\*/ )
{
$21 = $21
$73 = 0
}
else
for ( i = 1; i <= length($21); i++ ) {
if ( substr($21,i,1) ~ /[{}<>$@=,."\/\\&)(#*!~']/ ) {
$21 = substr($21,1,i - 1) " " substr($21,i + 1)
}
}
print $0
}
I called the awk script from a korn shell script using the follwoing syntax:
awk -f "name of awk script" input-file >output-file.
BTW, input file is tab delimited, "Customer name" attribute is field number 21 and "IS_VALID_CUST_NAME_F' is filed number 73.
Thanks again for the feedback.
I am posting the solution if anyone is interested.
AWK script:
BEGIN { FS = "\t"; OFS = "\t" }
{
if ( $21 ~ /^ / || $21 ~ /^___/ || $21 ~ /^[0-9]/ || $21 ~ /^\*/ )
{
$21 = $21
$73 = 0
}
else
for ( i = 1; i <= length($21); i++ ) {
if ( substr($21,i,1) ~ /[{}<>$@=,."\/\\&)(#*!~']/ ) {
$21 = substr($21,1,i - 1) " " substr($21,i + 1)
}
}
print $0
}
I called the awk script from a korn shell script using the follwoing syntax:
awk -f "name of awk script" input-file >output-file.
BTW, input file is tab delimited, "Customer name" attribute is field number 21 and "IS_VALID_CUST_NAME_F' is filed number 73.
Thanks again for the feedback.
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.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP