Clarification required on sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Clarification required on sed
# 1  
Old 02-03-2012
Clarification required on sed

Hi

Can some one tell what does this sed command do


sed 's/[]*[]$//g

I am more curious on the highlighted part , can some one explain what does that mean.

Thanks
Sri
# 2  
Old 02-03-2012
The final $ is an anchor, means end of the line. That's easy. Now the outer brackets:
Code:
[]*[]

mean "match any one of these characters".
E.g., if you have [abd], it will match any of the chars 'a', 'b', 'd'.
So the whole thing will strip (substitute with empty string) any trailing ],[,or * on the line (only one character).
'g' is unnecessary, because of the $ anchor, you cannot substitute any further.
And to make this syntactically correct, we need a closing single quote also.
Here:
Code:
$ echo 'sfj[dd]aa[][]*sd[667]qf[[]]*[]' | sed 's/[]*[]$//'
sfj[dd]aa[][]*sd[667]qf[[]]*[

To strip all the trailing ],[, or *, you just an *, quantifier:
Code:
$ echo 'sfj[dd]aa[][]*sd[667]qf[[]]*[]' | sed 's/[]*[]*$//'
sfj[dd]aa[][]*sd[667]qf


Last edited by mirni; 02-03-2012 at 04:41 AM.. Reason: added example
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

REGEX help required and some sed/awk help as well

Hi guys, I am coding a bash script that makes use of php scripts to pull URL's from a website. These url links will have numbers in them like 0.2.3 I want to make a regex that will yield me such numbers if I use a command like preg_grep. Question1: I need a regex that will tell my preg_grep... (2 Replies)
Discussion started by: mojoman
2 Replies

2. Shell Programming and Scripting

Tricky sed required

Hi All I need to put some sed together for a task and its a bit advanced for me, so I thought I'd ask if anyone here could help. I have a csv file with content like this - "","abcde","","" "'","abcde","","" "","","","1234" "'e'","","","" I need to remove any single quotes that fall... (17 Replies)
Discussion started by: steadyonabix
17 Replies

3. Shell Programming and Scripting

sed help required

Hi All, I have one file with below type of data in it, $ cat test.txt ###123 ###xyxytuerwb ###2 ###tyupe Here I would like to replace all the characters with "x" after the 3 "###" with the same number of characters. Can you please help me to achieve this. (7 Replies)
Discussion started by: gr8_usk
7 Replies

4. Shell Programming and Scripting

Clarification needed for a SED one liner

I want to use SED to replace all new line characters of a file, I googled and found this one liner sed '{:q;N;s/\n//g;t q}' infile what do :q;N; and t q mean in this script? (6 Replies)
Discussion started by: kevintse
6 Replies

5. Shell Programming and Scripting

clarification Required in Write command

Hi All, can you please help me to get clarified about the 'write' command. I have a script that sends a content of a file msg.txt to other user 'User B' using 'write' command. Script: ------ ..... cat msg.txt | write "user B" ..... Issue: I face a issue here, this scripts sends... (3 Replies)
Discussion started by: little_wonder
3 Replies

6. Shell Programming and Scripting

Help required with awk/sed

Hi I have a file, with format like: column1|coulumn2|column3|column4 A|X|K|18 L|O|R|31,42,25 G|H|I|55,66 L|E|Q|25,31,94 output required: column1|coulumn2|column3|column4 A|X|K|18 L|O|R|31,25 L|E|Q|25,31 Input File Format: All columns are seperated using |, last column... (8 Replies)
Discussion started by: New to awk
8 Replies

7. Shell Programming and Scripting

Help required in sed or awk.

Hi All, I need to pick up data on both sides of "=" sign. For eg, following is the context that I have. 125.156.125.147=machine1 147.125.185.156=machine2 147.125.185.159=machine3 Can I have the ip address in one variable and machine name in another variable using sed or awk. ... (1 Reply)
Discussion started by: nua7
1 Replies

8. Shell Programming and Scripting

Help in sed required.

Hi All, I am facing a small problem in sed. I want to insert a line in the existing file. Existing code: access to attr=userPassword by self write by * auth access to * by self write by users read by anonymous auth Desired code: access to attr=userPassword by self... (14 Replies)
Discussion started by: nua7
14 Replies

9. UNIX for Dummies Questions & Answers

Sed-- command help required

Hi Gurus, I have a small requirement. Let suppose i have a file test.txt test.txt contains Dispatched date = '2008-04-08' Name = 'Logers' Now i want to add one more line to it as Number of Responses = "$a" $a will be chnaging dynamically which i had grepped it in the script. Now i... (6 Replies)
Discussion started by: pssandeep
6 Replies

10. Shell Programming and Scripting

sed script required

Collegues I have a flat file with data in following structure. (S1 (S (NP (NP (DT The) (JJ beautiful) (NN view)) (PP (IN of) (NP (JJ outside) (NNP greenery)))) (VP (VBZ adds) (NP (DT a) (NN tranquil) (NN touch)) (PP (TO to) (NP (DT this) (NN place)))) (. .))) I have to extract the contents in... (2 Replies)
Discussion started by: jaganadh
2 Replies
Login or Register to Ask a Question