Sponsored Content
Homework and Emergencies Homework & Coursework Questions find grep sed commands homework Post 302493412 by ctsgnb on Wednesday 2nd of February 2011 04:26:25 PM
Old 02-02-2011
I give another one :

Code:
$ echo "jfaghkjfhadglkjaaaadfgdffffffdddttttmmmm" | sed 's/\(.\)\1*/\1/g'
jfaghkjfhadglkjadfgdfdtm

sed 's/\(.\)\1*/\1/g' explanations :

s/pattern1/pattern2/g substitute pattern1 with pattern2 in a global manner (even if pattern1 occurs more than once in a line
.matches any single character
\( \) what is inside these backslash protected parenthesis is stored in the string \1
\1 refer to what has just been matched
* what is just before is repeated 0 or more times
\1 stand for the pattern2 which refer to the matched caracter

If you want to remove only adding successive occurrenc of ... let's say only letters a or t :

Code:
$ echo "jfaghkjfhadglkjaaaadfgdffffffdddttttmmmm" | sed 's/\([at]\)\1*/\1/g'
jfaghkjfhadglkjadfgdffffffdddtmmmm


Last edited by ctsgnb; 02-02-2011 at 05:41 PM..
This User Gave Thanks to ctsgnb For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep and sed to find a pattern and add newline

Hello All, I have log file the result from a multithreaded process. So when a process finishes it will write to this log file as 123 rows merged. The issue is sometimes the processess finish at the same time or write to the file at the same time as 123 rows merged.145 rows merged. At... (5 Replies)
Discussion started by: ssikhar
5 Replies

2. UNIX for Dummies Questions & Answers

find and grep commands

I'm having trouble with the following commands i. count the number of lines which end in a 4 letter word grep '{4\}$' bfile <<seems to print out everything abc abc abcd joe joe john bob bill gregory greg greg gregory the grep command prints out the lines with 4 letter words and the... (3 Replies)
Discussion started by: StrengthThaDon
3 Replies

3. UNIX for Dummies Questions & Answers

help with find & grep commands

Folks; First about find: when i run this: find . -name '*log*' -mtime +10 -print | sed 's+^\./++;s+/.*++' | sort -u i got list of log files but also get a directories (although directory names doesn't have "log" in it). How can i exclude the directory from the output of this find command? ... (2 Replies)
Discussion started by: moe2266
2 Replies

4. Shell Programming and Scripting

Complex find grep or sed command

Haven't worked in bash for ages. did a good bit of shell scripting in regular sh, but have forgotten most of it. I have several thousand php files that now include the following line at the end of the file. There is no LF or CR/LF before it begins, it is just concatenated to the final line of... (3 Replies)
Discussion started by: sjburden
3 Replies

5. UNIX for Dummies Questions & Answers

using sed or grep to find exact match of text

Hi, Can anyone help me with the text editing I need here. I have a file that contains the following lines for example: (line numbers are for illustration only) 1 Hello world fantasy. 2 Hello worldfuntastic. 3 Hello world wonderful. I would like to get all those lines of text that... (5 Replies)
Discussion started by: risk_sly
5 Replies

6. UNIX for Advanced & Expert Users

Find, Grep and then Sed

Example: I have folders 456 abc xyz 123 a1b I dont want to find in 123 and a1b. From rest folder i need to find in html and php files. find ./ -path "123" -prune and a1b find ./ -iname "*.htm*" -o -iname "*.shtm*" -o -iname "*.php" Now while finding i need to grep multiple... (7 Replies)
Discussion started by: nxvir
7 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Wildcards used in find, ls and grep commands

Platforms : Solaris 10 and RHEL 5.6 I always get double quotes , single quotes and asteriks mixed up for find, ls and grep commands. The below commands retrieve the correct results. But , unders stress , I get all these mixed up :mad: .So, i wanted to get a clear picture. Please check if... (7 Replies)
Discussion started by: John K
7 Replies

8. Shell Programming and Scripting

Join two commands sed and grep

Hi all, I have two separate commands which I would like to join. Basically, I want to match a line and insert a character at the end of the previous line to the matched line Here is what I have gotgrep -B1 '^>' sed 's/$/*/' Any help is much appreciated thanks (5 Replies)
Discussion started by: kaav06
5 Replies

9. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

10. UNIX for Beginners Questions & Answers

How to find=grep or maybe sed/awk for multiple lines of text?

Hi, I am running the following: PASS="username/password" sqlplus -s << EOF | grep -v "^$" $PASS set feedback off set heading off set termout off select name from v\$database ; exit EOF Which gives ERROR: ORA-28002: the password will expire within 5 days PSMP1 (1 Reply)
Discussion started by: newbie_01
1 Replies
erl_format(3erl)						C Library Functions						  erl_format(3erl)

NAME
erl_format - Create and Match Erlang Terms DESCRIPTION
This module contains two routines - one general function for creating Erlang terms and one for pattern matching Erlang terms. EXPORTS
ETERM * erl_format(FormatStr, ... ) Types char *FormatStr; This is a general function for creating Erlang terms using a format specifier and a corresponding set of arguments, much in the way printf() works. FormatStr is a format specification string. The set of valid format specifiers is as follows: * ~i - Integer * ~f - Floating point * ~a - Atom * ~s - String * ~w - Arbitrary Erlang term For each format specifier that appears in FormatStr , there must be a corresponding argument following FormatStr . An Erlang term is built according to the FormatStr with values and Erlang terms substituted from the corresponding arguments and according to the individual format specifiers. For example: erl_format("[{name,~a},{age,~i},{data,~w}]", "madonna", 21, erl_format("[{adr,~s,~i}]","E-street",42)); This will create an (ETERM *) structure corresponding to the Erlang term: [{name,madonna},{age,21},{data,[{adr,"E-street",42}]}] The function returns an Erlang term, or NULL if FormatStr does not describe a valid Erlang term. int erl_match(Pattern, Term) Types ETERM *Pattern,*Term; This function is used to perform pattern matching similar to that done in Erlang. Refer to an Erlang manual for matching rules and more examples. Pattern is an Erlang term, possibly containing unbound variables. Term is an Erlang term that we wish to match against Pattern . Term and Pattern are compared, and any unbound variables in Pattern are bound to corresponding values in Term . If Term and Pattern can be matched, the function returns a non-zero value and binds any unbound variables in Pattern . If Term Pat- tern do not match, the function returns 0. For example: ETERM *term, *pattern, *pattern2; term1 = erl_format("{14,21}"); term2 = erl_format("{19,19}"); pattern1 = erl_format("{A,B}"); pattern2 = erl_format("{F,F}"); if (erl_match(pattern1, term1)) { /* match succeeds: * A gets bound to 14, * B gets bound to 21 */ ... } if (erl_match(pattern2, term1)) { /* match fails because F cannot be * bound to two separate values, 14 and 21 */ ... } if (erl_match(pattern2, term2)) { /* match succeeds and F gets bound to 19 */ ... } erl_var_content() can be used to retrieve the content of any variables bound as a result of a call to erl_match() . Ericsson AB erl_interface 3.7.3 erl_format(3erl)
All times are GMT -4. The time now is 11:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy