1

I want to read from standard input, delete all '/', and write the output to standard output. So, a file that contain:

/ab1/1a6/ 17
/a/b/1

will have output:

ab11a6 17
ab1

I think it should be something like this:

read input
sed -r 's/\/[^\/]*\/[^\/]*\/.*/"I not sure what do I need to put in here"/g'
echo $input

I don't really know what do I need to put the the "replace" section. any suggestion?

3 Answers 3

3
sed 's./..g'

This will delete all / characters on each line, so you don't need a replace section. You can either use the / as the delimiter and escape it in the text: s/\///g or choose a different punctuation symbol as a delimiter: s./..g

So if you want to transform a file called input.txt and write the output to output.txt:

sed 's./..g' input.txt > output.txt
# or
sed 's./..g' < input.txt > output.txt
Sign up to request clarification or add additional context in comments.

Comments

2

The simplest program to do what you've asked is:

 tr -d '/' 

If you enter that you will get what you wanted for output - no / characters You do not need a read or echo statement

sed will behave the same as others have shown, tr & sed read from stdin and write to stdout by default:

sed 's/\///g'

1 Comment

OP asked specifically for sed
1

Nothing... as shown below:

% echo "/ab1/1a6/ 17" | sed 's/\///g'
ab11a6 17

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.