tags:

views:

41

answers:

2

In my case

text:

21 130.104.72.201 3124 HTTP [C]±ÈÀûʱ ·¨Óï³ãëÌìÖ÷½Ì´óѧ 03-05 14:34 0.238
22 129.108.202.10 3128 HTTP [C]ÃÀ¹ú µÂ¿ËÈø˹´óѧ 03-05 14:08 1.983
23 130.88.203.27 3128 HTTP [C]Ó¢¹ú Âü³¹Ë¹ÌØ´óѧ 03-05 14:08 0.996
24 129.74.152.66 3124 HTTP [C]·¨¹ú ʥĸÂêÀûÑÇ´óѧ 03-05 14:08 0.922

command:

sed 's/HTTP.*://' ip_all02.txt

but nothing was deleted.

+3  A: 

What are you trying to do? That will remove everything from the first 'HTTP' to the last ':', like this:

21 130.104.72.201 3124 34 0.238
22 129.108.202.10 3128 08 1.983
23 130.88.203.27 3128 08 0.996
24 129.74.152.66 3124 08 0.922

...and the results will be dumped to stdout. If you want it in a new file, use > (scrap current contents) or >> (keep current contents) to redirect the output.

sed 's/HTTP.*://' ip_all02.txt > ip_all02_clean.txt
no
Or use "sed -i" to update in-place.
camh
Good point. I usually think of -i as being dangerous; I'd usually rather output to another file, check it out to make sure it looks alright, and then copy it back over the original file. Of course if you're dealing with multiple files in a deep directory structure that might not be practical.
no
Yes I want this result, but in my machine nothing happen.
bitshine
bitshine, it works fine for me. Maybe giving more details about exactly what you're doing and what results you're seeing would help.
no
+1  A: 

if you have gawk/awk on your CentOS, this is another viable option

awk '{gsub(/HTTP.*:/,"")}1' file
ghostdog74