Sponsored Content
Top Forums Shell Programming and Scripting How does this sed expression to remove non-alpha characters work? Post 302836629 by bgnersoon2be#1 on Wednesday 24th of July 2013 12:33:52 PM
Old 07-24-2013
How does this sed expression to remove non-alpha characters work?

Hello!

I know that this expression gets rid of non-alphanumeric characters:
Code:
sed 's/[^a-zA-z0-9]//g'

and I understand that it is replacing them with nothing - hence the '//'-, but I don't understand how it's doing it.
It seems it's finding strings that begin with alphanumeric and replacing them with nothing! Obviously that would not give the required output so I'm a little confused and clearly missing something...

Thanks for your help!

Last edited by Don Cragun; 07-24-2013 at 01:48 PM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: How do I remove leading non alpha characters

Hi, Sorry for silly question, but I'm trying to write a perl script to operate a log file that is in following format: (4)ab=1234/(10)bc=abcdef9876/cd=0.... The number in the brackets is the lenghts of the field, "/" is the field separator. Brackets are not leading every field. What I'm... (9 Replies)
Discussion started by: Juha
9 Replies

2. Shell Programming and Scripting

Sed replace characters not equal to an expression

Hi all, Suppose I have a file with the contents below, and I only want to print words %S_ then | sort -u. ------------------------------ The %S_MSG that starts with '%.*s' is too long. Maximum length is %d. The %S_MSG name '%.*s' contains more than the maximum number of prefixes. The... (5 Replies)
Discussion started by: poldo
5 Replies

3. Shell Programming and Scripting

grep or sed. How to remove certain characters

Here is my problem. I have a list of phone numbers that I want to use only the last 4 digits as PINs for something I am working on. I have all the numbers in a file but now I want to be removed all items EXCEPT the last 4 digits. I have seen sed commands and some grep commands but I am... (10 Replies)
Discussion started by: Sucio
10 Replies

4. Shell Programming and Scripting

non alpha characters in sed + making it fast?

hello, I'm trying to write the fastest sed command possible (large files will be processed) to replace RICH with NICK in a file which looks like this (below) if the occurance of RICH is uppercase, replace with uppercase if it's lowercase, replace with lowercase SOMTHING_RICH_SOMTHING <- replace... (10 Replies)
Discussion started by: rich@ardz
10 Replies

5. UNIX for Dummies Questions & Answers

sed command to remove characters help!

I am trying to analyse a large file of sequencing data, example of first 10 lines below, @HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1 GNCTATGGCTTGCCGGGCTCAGGGAAGACAATCATAGCCATGAAAATCATGGAAAAGATCAGAAAAACATTTCAA +HWUSI-EAS656_0044_FC:7:1:2447:1039#GCAATT/1... (1 Reply)
Discussion started by: Adeleh
1 Replies

6. Shell Programming and Scripting

Sed or trim to remove non alphanumeric and alpha characters?

Hi All, I am new to Unix and trying to run some scripting on a linux box. I am trying to remove the non alphanumeric characters and alpha characters from the following line. <measResults>883250 869.898 86432.4 809875.22 804609 60023 59715 </measResults> Desired output is: 883250... (6 Replies)
Discussion started by: jackma
6 Replies

7. Shell Programming and Scripting

Remove the Characters '[' and ']' with Sed

Hi, I am new to Sed and would like to know if it is possible to remove the characters . I have a couple of files with a keyword and would like to remove the substring. I am Using sed s/// but Its not working Thanks for your Support Andrew Borg (2 Replies)
Discussion started by: andrewborg
2 Replies

8. UNIX for Dummies Questions & Answers

sed remove expression from output I'm watching

I'm watching a particular expression as it is appended in a line to a file: tail -f LOG | sed -n /"$@"/p So whatever value I pass into this script will tail -f the file, but only show me lines that contain the value: lgwatch expression However some of the output contains a #20 control... (8 Replies)
Discussion started by: MaindotC
8 Replies

9. Shell Programming and Scripting

perl regular expression to remove the special characters

I had a string in perl script as below. Tue Augáá7 03:54:12 2012 Now I need to replace the special character with space. After removing the special chaacters Tue Aug 7 03:54:12 2012 Could anyone please help me here for writing the regular expression? Thanks in advance.. Regards, GS (1 Reply)
Discussion started by: giridhar276
1 Replies

10. Shell Programming and Scripting

Sed: -e expression #1, char 2: extra characters after command

Greetings.. getting the error while execution of the script, correct where i am missing #!/bin/bash DATE=`date +%Y-%m-%d:::%H:%M` HOSTNAME=`hostname` TXT="/log/temp.txt" LOGPATH="/log1/commanlogs/" IP=`/sbin/ifconfig | grep -i inet| head -n1| awk '{print $2}'| awk -F : '{print $2}'`... (7 Replies)
Discussion started by: manju98458
7 Replies
CTYPE_ALNUM(3)								 1							    CTYPE_ALNUM(3)

ctype_alnum - Check for alphanumeric character(s)

SYNOPSIS
bool ctype_alnum (string $text) DESCRIPTION
Checks if all of the characters in the provided string, $text, are alphanumeric. PARAMETERS
o $text - The tested string. RETURN VALUES
Returns TRUE if every character in $text is either a letter or a digit, FALSE otherwise. EXAMPLES
Example #1 A ctype_alnum(3) example (using the default locale) <?php $strings = array('AbCd1zyZ9', 'foo!#$bar'); foreach ($strings as $testcase) { if (ctype_alnum($testcase)) { echo "The string $testcase consists of all letters or digits. "; } else { echo "The string $testcase does not consist of all letters or digits. "; } } ?> The above example will output: The string AbCd1zyZ9 consists of all letters or digits. The string foo!#$bar does not consist of all letters or digits. NOTES
Note If an integer between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character (negative val- ues have 256 added in order to allow characters in the Extended ASCII range). Any other integer is interpreted as a string contain- ing the decimal digits of the integer. SEE ALSO
ctype_alpha(3), ctype_digit(3), setlocale(3). PHP Documentation Group CTYPE_ALNUM(3)
All times are GMT -4. The time now is 02:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy