Basic sed doubts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Basic sed doubts
# 1  
Old 09-26-2013
Basic sed doubts

Hi,

I am a newbie to sed environment.
Have been trying to understand some basics of the language,

I am required to replace the occurence of a text string with 0...the command that has been told to me is this
Code:
"s/^\s<=k/0/" -e

Can some one please explain me how to
break the command for understanding. AS in

I do know that s is used for substitution and ^ is used to
indicate the begining of the string or something.
Can someone please tell what is the utility of \s.

TIA

Last edited by Scott; 09-26-2013 at 07:38 AM.. Reason: Fixed code tags
# 2  
Old 09-26-2013
  • ^ ... begin of line, as you already pointed out
  • \s ... whitespace character (blank, tab)
  • <=k ... a string literal
This User Gave Thanks to hergp For This Post:
# 3  
Old 09-26-2013
sorry to bug u again

Code:
s/,[ ]*?[ ]*,/, ,/g

what does this do ?

Smilie

Last edited by Scott; 09-26-2013 at 07:39 AM.. Reason: Fixed code tags
# 4  
Old 09-26-2013
Substitute the sequence
  • , ... one comma
  • [ ]* ... zero or more blanks
  • ? ... a question mark
  • [ ]* ... zero or more blanks
  • , ... one comma
with
  • , , ... the string comma-blank-comma
and g ... do it for all matches in a line, not only the first
These 2 Users Gave Thanks to hergp For This Post:
# 5  
Old 09-27-2013
A new question used to appear at the end of this thread. It has been moved here.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Basic sed usage in shell script

Hi, A basic sed question. I have a set of files. In each file there is a number that I want replaced. For example, if I run sed I should get the following: % cat test2.txt #goofy//171.00 goofy 171.00 % sed -i 's/171/xxx/g' test2.txt % cat test2.txt #goofy//xxx.00 goofy xxx.00 ... (2 Replies)
Discussion started by: pc2001
2 Replies

2. UNIX for Dummies Questions & Answers

sed basic doubt

Hi , what is the equivalent of below awk in sed. awk '$1=="ABC"&&$2=="XYZ" {print $0}' infile Thanks, Shruthi (6 Replies)
Discussion started by: shruthidwh
6 Replies

3. Shell Programming and Scripting

Basic sed question

Please have a look at below examples. Why do these 3 sed commands deliver the same result? Especially, why are there 4 "x" in the result instead of 3? 1. echo "abc" | sed 's/d*/x/g' xaxbxcx 2. echo "abc" | sed 's/d*/&x/g' xaxbxcx 3. echo "abc" | sed 's/d*/x&/g' xaxbxcx Thanks for... (2 Replies)
Discussion started by: Werner Gross
2 Replies

4. Shell Programming and Scripting

a very basic sed one-liner...that isn't working :-(

Greetings all. :) I would like to use sed to join all non-blank lines together in a particular file. I was thinking I could do this by simply replacing the terminating, new-line character on every line which is not blank, but I must be missing something in my sed line: $ sed... (3 Replies)
Discussion started by: SteveB-in-LV
3 Replies

5. Shell Programming and Scripting

awk, sed and a shell doubts

Hi, I have 3 doubts which I posted it here. Doubt 1: I have a file containing data: 22 -73 89 10 99 21 15 -77 23 63 -80 91 -22 65 28 97 I am trying to print the fields in the reverse order and replace every field by its absolute (positive) value (ie.) I am looking for output: 10... (8 Replies)
Discussion started by: royalibrahim
8 Replies

6. Shell Programming and Scripting

Basic SED doubt

Hi Friends!! I want to add a / at the end of a number. for example i have CQ65758 /, in this case i want to shift that backspace one space to the left so the my result becomes CQ65758/. How can i do that with sed. Thanks Adi (3 Replies)
Discussion started by: asirohi
3 Replies

7. UNIX for Dummies Questions & Answers

Basic doubts related to Unix

Hi all, I have few question related to Unix environment and commands : 1. what is .chrc file contain and if it is not present then what happens. 2. what is .login file contain,in which dir it is present and what all other uses are their for this file 3. how and who calls .profile when you... (2 Replies)
Discussion started by: ravi.sadani19
2 Replies

8. Shell Programming and Scripting

Basic sed replace question

Hello, I have a .htaccess file as follows... No I want to comment the last line ( in this case.. it may not be a last line for other cases).. please advise how to add a # (comment infront of "Options All -Indexes" not assuming this line to be the last line using sed. root@server1 # cat... (13 Replies)
Discussion started by: fed.linuxgossip
13 Replies
Login or Register to Ask a Question