Sponsored Content
Full Discussion: Simple String Manipulation
Top Forums UNIX for Dummies Questions & Answers Simple String Manipulation Post 302435158 by zaxxon on Tuesday 6th of July 2010 01:49:52 PM
Old 07-06-2010
Like this?
Code:
$> echo 123D| sed 's/[[:digit:]]//g'
D
$> echo 123D| sed 's/[[:alpha:]]//g'
123

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract 100 from first field in long list? Simple manipulation?

It sounds so easy to do. I have a file thats laid out like this.. number text text text text (etc about 15 times with various text fields) I want to take the first field, "number", subtract 100 from it, and then put it back in the file. a simple little manipulation of the first field in... (4 Replies)
Discussion started by: LordJezo
4 Replies

2. Shell Programming and Scripting

string manipulation

Hello, I have a korn shell string variable str1 = "A,B,Z" I would like to create another korn shell string variable str2 = "letter = 'A' or letter = 'B' or letter = 'Z' " Please help! Thanks in advance an UNIX newbie! (13 Replies)
Discussion started by: hai1973
13 Replies

3. Shell Programming and Scripting

String Manipulation Help

Hey Guys, Right i know how to alter a word to begin with a capital letter, i know how to remove unwanted characters and replace them with the relevant character however i don't now if there is a way to do them all in one line. Code: echo -n ${string:0:1} | tr a-z A-Z #convert first letter... (4 Replies)
Discussion started by: shadow0001
4 Replies

4. Shell Programming and Scripting

string manipulation

if I have two string variable, how do I add one to anther. like a= "a" b="b" c=$a+$b but that doesn't work. Is there anyway to solve it.http://www.qtl.co.il/img/copy.pnghttp://www.google.com/favicon.icohttp://www.babylon.com/favicon.icohttp://www.morfix.com/favicon.ico (2 Replies)
Discussion started by: programAngel
2 Replies

5. Homework & Coursework Questions

String Manipulation

Write a shell program to display the position of the right - most character in a given input string. Example : Input : RAHUL Output : L is in the 5th position also tell me how to count length of string and how to find the position of specific character in left most side. Homework... (0 Replies)
Discussion started by: shashwat2691
0 Replies

6. Shell Programming and Scripting

string manipulation

hi all, i am new to shell scripting and need help. i have a string that stores the month in Jan/Feb/Mar format. i need to convert it to number like 01 for jan, 12 for dec etc. i am using the following sed command, echo "Enter a Month eg. Jan/Feb : " read MONTHEND ... (9 Replies)
Discussion started by: anupom2000
9 Replies

7. Shell Programming and Scripting

Simple string manipulation

Hello, I would like to make simple string manipulation but since i am new in shell scripting some strange stuff are uncomprehensible to me: I would like to pick up the name of a file and put it in a variable: shadok@computer:~$a= folder/fil*.dat shadok@computer:~$echo $a... (3 Replies)
Discussion started by: shadok
3 Replies

8. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

9. Shell Programming and Scripting

String manipulation

Hi , I am getting a string like aaa,bbb,sdsdad,sdfsdf,sdfsdfdsf,rtyrtyr,45654654,ddfdfdfgdfg,dfgdfgdg........... Now what I need is to format it. So after each nth comma I need one newline. So the above will look like when n=3 aaa,bbb,sdsdad, sdfsdf,sdfsdfdsf,rtyrtyr,... (4 Replies)
Discussion started by: Anupam_Halder
4 Replies

10. Shell Programming and Scripting

String Manipulation

I'm making a little game in Perl, and I am trying to remove the first instance of a character in an arbitrary string. For example, if the string is "cupcakes"and the user enters another string that contains letters from "cupcake" e.g: "sake"the original string will now look like this (below)... (3 Replies)
Discussion started by: whyte_rhyno
3 Replies
EREG_REPLACE(3) 							 1							   EREG_REPLACE(3)

ereg_replace - Replace regular expression

SYNOPSIS
string ereg_replace (string $pattern, string $replacement, string $string) DESCRIPTION
This function scans $string for matches to $pattern, then replaces the matched text with $replacement. Warning This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. PARAMETERS
o $pattern - A POSIX extended regular expression. o $replacement - If $pattern contains parenthesized substrings, $replacement may contain substrings of the form digit, which will be replaced by the text matching the digit'th parenthesized substring; will produce the entire contents of string. Up to nine substrings may be used. Parentheses may be nested, in which case they are counted by the opening parenthesis. o $string - The input string. RETURN VALUES
The modified string is returned. If no matches are found in $string, then it will be returned unchanged. EXAMPLES
For example, the following code snippet prints "This was a test" three times: Example #1 ereg_replace(3) example <?php $string = "This is a test"; echo str_replace(" is", " was", $string); echo ereg_replace("( )is", "\1was", $string); echo ereg_replace("(( )is)", "\2was", $string); ?> One thing to take note of is that if you use an integer value as the $replacement parameter, you may not get the results you expect. This is because ereg_replace(3) will interpret the number as the ordinal value of a character, and apply that. For instance: Example #2 ereg_replace(3) example <?php /* This will not work as expected. */ $num = 4; $string = "This string has four words."; $string = ereg_replace('four', $num, $string); echo $string; /* Output: 'This string has words.' */ /* This will work. */ $num = '4'; $string = "This string has four words."; $string = ereg_replace('four', $num, $string); echo $string; /* Output: 'This string has 4 words.' */ ?> Example #3 Replace URLs with links <?php $text = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", '<a href="\0">\0</a>', $text); ?> NOTES
Note As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED notice. See the list of differences for help on converting to PCRE. Tip ereg_replace(3) is deprecated as of PHP 5.3.0. preg_replace(3) is the suggested alternative to this function. SEE ALSO
ereg(3), eregi(3), eregi_replace(3), str_replace(3), preg_replace(3), quotemeta(3). PHP Documentation Group EREG_REPLACE(3)
All times are GMT -4. The time now is 07:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy