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
# 1  
Old 04-04-2007
SED command to change ./ to a space

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

Thanks very much for you help on this!
BobK
./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
# 2  
Old 04-04-2007
Try this:
sed 's!./!!' input_file > output_file
# 3  
Old 04-04-2007
Code:
echo './_ABMSTR.TXT' | sed 's#^[.]/##'

# 4  
Old 04-04-2007
Wow that's great thanks alot all for the help, works great!

Have a great week!

BobK
# 5  
Old 04-04-2007
Quote:
Originally Posted by Shell_Life
Try this:
sed 's!./!!' input_file > output_file
Shell_Life, there are a couple of things wrong with that.

1. '.' will match ANY character so you would be replacing every occurrence of / and its preceding character with a space.
2. You didn't bind to the start of the line, so if the pattern didn't happen at the start of a line, you could make a replacement in error elsewhere.

Last edited by reborg; 04-04-2007 at 06:28 PM..
# 6  
Old 04-04-2007
reborg, thank you for analizing my solution.

You are absolutely right when you said that I didn't bind to the start of
the line with caract (^) -- when I tought about the solution I was only
looking at the data which every line always begins with "./".

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?

reborg, you are a real player here -- thank you.
# 7  
Old 04-04-2007
so if the 'first occurrence' happens to be in the middle of a line/string:
Code:
$ echo '_ABMSTR./TXT' | sed 's!./!!'
_ABMSTRTXT

Yes, you do need to 'anchor' the regex to the beginning of the line.
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