I have converted a HTML page<http://www.imdb.com/chart/top> which consisted of the movie names using a pipelined SED commands to retrieve only the table as shown in the page.
Here is the o/p so far I have got
.......
|22.|8.7|The Usual Suspects|(1995)|239,740|
|23.|8.7|Psycho|(1960)|126,928|
|24.|8.6|The Silence of the Lambs|(1991)|217,130|
|25.|8.6|Sunset Blvd.|(1950)|47,585|
|26.|8.6|The Matrix|(1999)|338,524|
|27.|8.6|Memento|(2000)|238,630|
|28.|8.6|Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb|(1964)|141,831|
........
As can be seen, the o/p shows how the table of movies look on the HTML page.
My query is how to remove the trailing '.' in the first field i.e. rank field of the o/p.
So the expected o/p is :
|22|8.7|The Usual Suspects|(1995)|239,740|
|23|8.7|Psycho|(1960)|126,928|
|24|8.6|The Silence of the Lambs|(1991)|217,130|
|25|8.6|Sunset Blvd.|(1950)|47,585|
|26|8.6|The Matrix|(1999)|338,524|
|27|8.6|Memento|(2000)|238,630|
|28|8.6|Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb|(1964)|141,831|
Please remember,
1> The command should remove the trailing dot of the 1st field ONLY.
2 > The rank field ranges from 1 to 250 in value.
Not sure what -i does. But its anyways replacing the values in 2nd column as well. As mentioned, it needs to affect the 1st column only to remove the trailing dots after ranlk field i.e. 1st field
Please let me know if any information is needed to resolve the query
And the command is affecting the second column as well. Please have a look at the o/p
|1|9.|The Shawshank Redemptio|(1994|447,83|
|2|9.|The Godfathe|(1972|367,05|
|3|9.|The Godfather: Part I|(1974|214,88|
|4|8.|Il buono, il brutto, il cattivo|(1966|134,48|
Its not working
1 > The values of 2nd field are lost.
2 > For some reason, the closing parenthesis are erased.
[house@leonov] sed 's/.|/|/' -i table.file
[house@leonov] cat table.file
|22|8.7|The Usual Suspects|(1995)|239,740|
|23|8.7|Psycho|(1960)|126,928|
|24|8.6|The Silence of the Lambs|(1991)|217,130|
|25|8.6|Sunset Blvd.|(1950)|47,585|
|26|8.6|The Matrix|(1999)|338,524|
|27|8.6|Memento|(2000)|238,630|
|28|8.6|Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb|(1964)|141,831|
$ cat file
|22.|8.7|The Usual Suspects|(1995)|239,740|
|23.|8.7|Psycho|(1960)|126,928|
|24.|8.6|The Silence of the Lambs|(1991)|217,130|
|25.|8.6|Sunset Blvd.|(1950)|47,585|
|26.|8.6|The Matrix|(1999)|338,524|
|27.|8.6|Memento|(2000)|238,630|
|28.|8.6|Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb|(1964)|141,831|
$ sed 's/.|/|/' file
|22|8.7|The Usual Suspects|(1995)|239,740|
|23|8.7|Psycho|(1960)|126,928|
|24|8.6|The Silence of the Lambs|(1991)|217,130|
|25|8.6|Sunset Blvd.|(1950)|47,585|
|26|8.6|The Matrix|(1999)|338,524|
|27|8.6|Memento|(2000)|238,630|
|28|8.6|Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb|(1964)|141,831|
Sir, here is my pipelined SED so far to convert the HTML page to the o/p mentioned in Post 1.
sed '/Top 250 movies/!d' top250.html | sed 's/^.<\/b><\/font><\/td><\/tr>//' | sed 's/<\/table>.$//' | sed 's/<\/tr>$//' | sed 's/<\/tr>/#/g' | sed 's/<[^>]*>/ /g' | sed 's/ \{2,\}/|/g' | sed 's/.|/|/' -i | cat
I am not sure of -i option and its giving me the following error:
sed: no input files
What changes need to done to this?
---------- Post updated at 08:18 AM ---------- Previous update was at 08:12 AM ----------
I am not sure Sir. But
sed 's/.|/|/' file - > is changing only the 1st occurence.
WHen I change this command to sed 's/.|/|/g' , I get the following o/p
|1|9.|The Shawshank Redemptio|(1994|447,83|
As noticed, the 1st character of all the fields go missing
Sir, it was only changing the 1st occurrence of the rank field.
i.e. was getting |1|9.1| ... but then the next values continued to be the same
i.e. |2.|9.1| ....
I made the following change and now its working fine
sed 's/\.|/|/'
Thanks a lot everyone !!
---------- Post updated at 03:14 PM ---------- Previous update was at 08:36 AM ----------
How to use grep to retrieve a particular column.
Like for the following intermediate o/p:
29|8.6|North by Northwest|1959|83372
30|8.6|Se7en|1995|244038
31|8.6|Its a Wonderful Life|1946|90888
32|8.6|The Lord of the Rings: The Two Towers|2002|292149
33|8.6|Citizen Kane|1941|126588
the 1st column is the rank of movie, 2nd is the rating and 3rd is the Movie name.
I need to retrieve the 3rd column using grep and count no. of words in the movie name.
How to go about this?
---------- Post updated at 07:38 PM ---------- Previous update was at 03:14 PM ----------
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.