Remove characters from text

I have a file which looks like this. I only show first 11 lines of the file followed by some text that appears at the end of every file.

1. file:///path1/path2/path3/path4/251192.dat (score 3.849384, docid 142923)
2. file:///path1/path2/path3/path4/173859.dat (score 3.831033, docid 75365)
3. file:///path1/path2/path3/path4/120815.dat (score 3.770058, docid 19773)
4. file:///path1/path2/path3/path4/178982.dat (score 3.643835, docid 80750)
5. file:///path1/path2/path3/path4/188878.dat (score 3.599508, docid 91201)
6. file:///path1/path2/path3/path4/160844.dat (score 3.582469, docid 61641)
7. file:///path1/path2/path3/path4/153125.dat (score 3.581480, docid 53507)
8. file:///path1/path2/path3/path4/209083.dat (score 3.576286, docid 108580)
9. file:///path1/path2/path3/path4/189989.dat (score 3.556764, docid 92369)
10. file:///path1/path2/path3/path4/169844.dat (score 3.528978, docid 71137)
11. file:///path1/path2/path3/path4/157264.dat (score 3.505972, docid 57873)

2000 people took part and  of 144690 shown (took 0.021768 time)
21813 people included (excluding loading/unloading)

I want my output to be like this:

/path1/path2/path3/path4/251192.dat 3.849384
/path1/path2/path3/path4/173859.dat 3.831033
/path1/path2/path3/path4/120815.dat 3.770058
/path1/path2/path3/path4/178982.dat 3.643835
/path1/path2/path3/path4/188878.dat 3.599508
/path1/path2/path3/path4/160844.dat 3.582469
/path1/path2/path3/path4/153125.dat 3.581480
/path1/path2/path3/path4/209083.dat 3.57628
/path1/path2/path3/path4/189989.dat 3.556764
/path1/path2/path3/path4/169844.dat 3.528978
/path1/path2/path3/path4/157264.dat 3.505972

This is what I have tried:

sed 's/^\s*[0-9]\ file:////' FILENAME

I think this will remove the number and "file://" characters from the file but not sure how to chop off the other part of the text.
I am using Linux with BASH.

sed -n '/file:/s/^.*file:\/\/\(.*dat\).*(score \(.*\),.*/\1 \2/p' FILENAME
1 Like
$ ruby -ne 'print $_.gsub(/.*file:\/\/\/|\(score|,\s+docid.*$/,"") if /^\d+\./' file
path1/path2/path3/path4/251192.dat  3.849384
path1/path2/path3/path4/173859.dat  3.831033
path1/path2/path3/path4/120815.dat  3.770058
path1/path2/path3/path4/178982.dat  3.643835
path1/path2/path3/path4/188878.dat  3.599508
path1/path2/path3/path4/160844.dat  3.582469
path1/path2/path3/path4/153125.dat  3.581480
path1/path2/path3/path4/209083.dat  3.576286
path1/path2/path3/path4/189989.dat  3.556764
path1/path2/path3/path4/169844.dat  3.528978
path1/path2/path3/path4/157264.dat  3.505972

1 Like

with multiple commands :slight_smile:

$ grep "^[0-9]\." inputfile | nawk -F"[/,]" ' { print "/"$4"/"$5"/"$6"/"$7"/"$8 } '| sed 's,(score ,,g'
1 Like

Might as well include an example in awk....

awk ' { gsub("file://","",$2) ; printf("%s %g\n",$2,$4)} ' filename
1 Like