-3

Hi I have a problem as I want to delete by sed or maybe by another command all between space and c

85.89.161.147 [11/cdlinux-0.5.8.iso

so I want to leave 85.89.161.147 cdlinux-0... I've tried other people tips but none of them have worked for me. Any ideas? I would also ask you to explain why this way as I'm studying Linux now so it would help me a lot:)

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • _I've tried other people tips but none of them have worked for me. Any ideas?_ - what have you tried so far? This will help to not give you duplicate adivce – Benni Apr 05 '20 at 23:28
  • Welcome to Stack Overflow. SO is a question and answer page for professional and enthusiastic programmers. Add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself. – Cyrus Apr 05 '20 at 23:29
  • well man, my task is to count the versions of linux downloaded I've already done it the other way but good results vary a little bit so I'm searching for a better result. I have no clue how should it be correctly done – Bartek Juśkiewicz Apr 05 '20 at 23:33
  • so in my case i have thousands of the same lines as in my question and i have to count them using uniq -c but firstly i have to uniq duplicated downloads the same version from the same ip so i have to leave it as I asked in the question := ) – Bartek Juśkiewicz Apr 05 '20 at 23:35
  • i've already tried sed -n '/Here/,/String/p' but instead of here and string i used space and c – Bartek Juśkiewicz Apr 05 '20 at 23:35
  • then tried something like this "Hello world xxx this is a file yyy" | sed 's/.*xxx \(.*\)yyy/\1/' but I have no clue how it works so I would be pleasant if somebody gave me an answer and explain a little bit – Bartek Juśkiewicz Apr 05 '20 at 23:36
  • If you want my code, cat cdlinux.www.log | grep " 200" | cut -d "/" -f 1,8 | cut -d ":" -f 2 | sort -u | grep "\.iso" | cut -d "H" -f 1 | cut -d " " -f 1,4 this is my code so far but it surely wouldn't help you answering my question – Bartek Juśkiewicz Apr 05 '20 at 23:37
  • `sed 's/\[[[:digit:]]\+\///'` hope this helps – Hernan Garcia Apr 05 '20 at 23:38
  • okay, then can you help me understand this line? step by step please? – Bartek Juśkiewicz Apr 05 '20 at 23:39
  • 1
    `s` is substitute command. now regex is as follows: `\[` is bracket escaped, `[[:digit:]]\+` matches all the numbers, `\/` is forward slash escaped and finally `//` is substitute with empty string :) – Hernan Garcia Apr 05 '20 at 23:44
  • thank you very much ! It worked for me – Bartek Juśkiewicz Apr 05 '20 at 23:48
  • 1
    Going forward, try to focus your questions on the thing you're trying to accomplish, not the tools you imagine the person answering might choose to use for the job. Sometimes `sed` is the right tool for the job, but sometimes it's better to use `awk`, or `grep`, or even bash's built-in regex support. – Charles Duffy Apr 05 '20 at 23:49
  • That question lacks the context. For example, what should be done of `a dc xc`? Should the output be `a c xc` or `a c`? – Quasímodo Apr 05 '20 at 23:51

1 Answers1

1

hope this helps

sed 's/\[[[:digit:]]\+\///'

s is substitute command. now regex is as follows: \[ is bracket escaped, [[:digit:]]\+ matches all the numbers, \/ is forward slash escaped and finally // is substitute with empty string :)

Hernan Garcia
  • 1,416
  • 1
  • 13
  • 24
  • In [How to Answer](https://stackoverflow.com/help/how-to-answer), note the section *Answer Well-Asked Questions*, and therein the bullet point regarding questions that "have been asked and answered many times before". (Likewise the bullet point about questions that don't identify a specific problem; ideally, the OP would have showed what they tried, and exactly how it failed). – Charles Duffy Apr 05 '20 at 23:51