SED command to change ./ to a space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED command to change ./ to a space
# 8  
Old 04-04-2007
Quote:
Originally Posted by Shell_Life
As for the other observation, the solution does not replace "every occurrence"
of "/" in the line -- it only replaces the first one, as I didn't suffixed the "s"
command with "g" -- do you agree?
Correct, I misspoke, I meant that it would replace the first / and ANY letter preceding it, irrespective of where it happened in the string. Essentially I was commenting on the use of . (if the first / was at the start of the line, it would replace the second / and it's preceding character)

Last edited by reborg; 04-04-2007 at 07:33 PM..
# 9  
Old 04-04-2007
vgersh, the user bobk wrote his request/specification as follows:
"Hello, i'm trying to remove the ./ from this file using this SED command:
...
./REVISED/_C5MSTR.TXT.out
./REVISED/_MCMSTR.TXT.out
./_ABMSTR.TXT.out
./_ADMSTR.TXT.out
./_AQMSTR.TXT.out
./_BAMSTR.TXT.out
./_C2MSTR.TXT.out
./_C3MSTR.TXT.out
./_C4MSTR.TXT.out
./_CBMSTR.TXT.out
./_CFMSTR.TXT.out
./_CGMSTR.TXT.out

From what he wrote, the conclusion is:
Nowhere in his request/specification, he said where the "./" was going to
be located in each record.

One can only make an assumption that the location of the "./" is in the
beginning of each record, by looking at the sample file he gave.

If we can only go for what is written by him and the sample file he gave
as an example, we can also conclude that the "./" will always appear as
the first and second characters in each record, nowhere else.

Consequently, forcing "sed" to search for "./" at the beginning of each
record is meaninless, as we know it will always be there.

For almost every program that is written, several arguments can be made
starting with "what if" that are not in the specifications, such as:
"so if the 'first occurrence' happens to be in the middle of a line/string"

We know this statement is not true, as per bobk specification.
# 10  
Old 04-05-2007
Quote:
Originally Posted by bobk544
Hello, i'm trying to remove the ./ from this file using this SED command:

sed 's/.///g' all3.lst > all4.lst

Does anyone know the correct format for this?

For example, i'm trying to convert ./_ABMSTR.TXT.out to:
_ABMSTR.TXT.out

./REVISED/_C5MSTR.TXT.out
./REVISED/_MCMSTR.TXT.out
./_ABMSTR.TXT.out
...
./_CFMSTR.TXT.out
./_CGMSTR.TXT.out

If you want to remove the first two characters from every line:
Code:
sed 's/^..//' all3.lst > all4.lst

If you want to remove "./" from the front of every line, but remove nothing if the line doesn't start with "./":
Code:
sed 's|^\./||' all3.lst > all4.lst

If you want to remove the first occurrence of "./" from every line (wherever it occurs on the line):
Code:
sed 's|\./||' all3.lst > all4.lst

If you want to remove all occurrences of "./" from the file:
Code:
sed 's|\./||g' all3.lst > all4.lst

# 11  
Old 04-05-2007
Shell_Life,
based on my own experience, most of the OPs asking how to use regex and/or sed for editing start their queries with the very ambiguous definitions of the 'tasks at hand'. As solutions are proposed, in most cases (not all of them and not all the time) it becomes evident that a simply solutions (without considering the hypotheticals in the form of 'what if) will simply not scale. And the threads will go on and on with the numerous tweaks to the regex along the way.

As I said in most cases the OPs don't "see" the repetitive patterns and cannot identify the 'trends'. So I try to assume the "pattern" if I do see it and in most cases (once again - not all the cases and not all the time) it is what the OPs want.

Once again - "your mileage may vary". You can most certainly approach the answer differently like either your response (making no assumptions) or like what cfajohnson just posted (rephrasing the initial question with different 'twists" and answering them one-by-one in order and let the OP choose the interpretation of his/her/its original question for themselves). BTW, I do prefer the latter (but in most cases I simply don't have the patience to do it consistently) - thanks Chris.

It all comes down to the posting "style". If someone has the desired, the patience and the stamina to answer every OPs question in the very detailed manner - all the power to him/her - it will only benefit the greater community and these forums. I simply try to do my own best in the manner that I find fit based on 2 factors:
  1. time and availibility
  2. judgement call of the original posting - if I feel/see that the OP spent enought time and effort analyzing and phrasing his/her/its question in the detailed manner - it's a clear indication (at least to me) that the OP deserves a detailed thorough answer. On the other hand, if the question is vague (in my eyes), I make my own assumptions based on my own experience and post a 'quick and dirty' solution. In the latter case, the experience shows that most of the OPs are 'transient' and don't care about understanding the specifics of the solution and don't respond with more detailed questions.
Sorry for going on the tangent here.....

Last edited by vgersh99; 04-05-2007 at 04:48 AM..
# 12  
Old 04-05-2007
vgersh99,
Now I know why you are a moderator!
Your thoughts are logical and precise.
I guess we all agree that the OPs must start with a very clear specification
of what they want, but as we all know, this is almost impossible to have
enforced.
My purpose here is to try to help with what I can and also to learn other
ways of solving problems.
I will continue to offer solutions, having in mind that the OPs requests may
only be the tip of the iceberg of a larger problem.
Thank you for clarifying vgersh99.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command not working for me to change text in a file

UNIX gurus I need your help with the following (The server is an AIX box). I have a text file with the following information: ******************************************************** SOME LINES case :WORD1 SOME LINES :WORD2 SOME LINES :WORD3 SOME LINES esac SOME LINES... (7 Replies)
Discussion started by: curiousmal
7 Replies

2. Shell Programming and Scripting

sed command: change only twice

Hello, I recently sought help on another thread about how to prefix 2 words in a file with 'pack/'. This is the command: sed --in-place 's/"\(libraries\|objects\)"/"pack\/\1"/g' Background: I have a .json file with the word 'libraries' and 'objects' in it. However, 'libraries' occurs twice;... (6 Replies)
Discussion started by: AJ Ruckman
6 Replies

3. Shell Programming and Scripting

SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command sed 'pattern c\ new line ' <file1 >file 2 I got two questions 1. how do I insert a blank space at the beginning of new line? 2. how do I use this command to execute multiple command using the -e... (5 Replies)
Discussion started by: piynik
5 Replies

4. UNIX for Advanced & Expert Users

Insert 1 space using the command sed

Hi I want to use sed to insert one space after the 10'th character in every line. The lines are on this format: 2012-01-1012:30:55|7323456|65432 2011-02-0313:11:06|1223|3456 ...... ...... Does anyone know sed well enough to acomplish this? If there is any other way around this... (7 Replies)
Discussion started by: ic12
7 Replies

5. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

6. Shell Programming and Scripting

Format of SED command to change a date

I have a website. I have a directory within it with over a hundred .html files. I need to change a date within every file. I don't have an easy way to find/replace. I need to change 10/31 to 11/30 on every single page at once. I tried the command below but it didn't work. Obviously I don't know... (3 Replies)
Discussion started by: ijustsawmars
3 Replies

7. Shell Programming and Scripting

How to use sed command for change special lines?

Hi, I want to add a character "#" in this few lines with sed command Initial: ### CACCIA: DEBUT ### if $(grep -wqi "$2" /etc/passwd); then chuser -R files registry=files $2 fi ### CACCIA: FIN ### Result with sed command: ### CACCIA: DEBUT ### #if $(grep -wqi "$2"... (4 Replies)
Discussion started by: khalidou13
4 Replies

8. Shell Programming and Scripting

Using sed command to change end of line

I am looking to change a data file into a javascript string and this is the code that I am using: sed -i '' -e 's/^/str += "/' -e 's/$/";/' file.xml The first part -e 's/^/str += "/' works as intended, but the second part -e 's/$/";/' adds an additional newline to my file, so that instead of... (3 Replies)
Discussion started by: figaro
3 Replies

9. Shell Programming and Scripting

how to change the name of the file which is having space in between

how to change the name of the file which is having space in between i have a file name called. san con.cfg ( since it cannot be opened ) i want to rename it to san_con.cfg i tried to cat and mv .. but not working (3 Replies)
Discussion started by: mail2sant
3 Replies

10. Shell Programming and Scripting

sed command to change 2nd field

Hi I am a beginner to sed command, here I have a question about using sed to add a few characters into a token of a string. For example, I have a file, sqw:qqq:123124:uiqe dfd:ccc:12390:dfjis cde:aaa:21311:dfjsid and, I want the output to be, sqw:qqq:123124:uiqe... (4 Replies)
Discussion started by: Julius
4 Replies
Login or Register to Ask a Question