Help using SED command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help using SED command
# 8  
Old 10-15-2009
^^

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 ----------

Quote:
Originally Posted by Franklin52
This is what I get:

Code:
$ 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|

Is there something wrong?

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
# 9  
Old 10-15-2009
Quote:
Originally Posted by sh_kk
I am not sure Sir. But

sed 's/.|/|/' file - > is changing only the 1st occurence.
I really don't understand the problem.

Is the output in my last post not the desired output?
# 10  
Old 10-15-2009
Quote:
Originally Posted by Franklin52
I really don't understand the problem.

Is the output in my last post not the desired output?

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 ----------

Hiii... Can anyone please help out?
# 11  
Old 10-19-2009
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Try this:

Code:
awk -F"|" '/Lord of the Rings/{print split($3,a," ")}' file

# 12  
Old 10-19-2009
@sh_kk:


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 [code] and [/code] 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.

Thank You.

The UNIX and Linux Forums
# 13  
Old 10-19-2009
with bash
Code:
while IFS="|" read -r a b c
do
    echo "$a|${b%*.}|$c"
done < "file"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output of sed command to another sed command

Hi All, I'm relatively new to Unix scripting and am trying to get my head around piping. I'm trying to take a header record from one file and prepend it to another file. I've done this by creating several temp files but i'm wondering if there is a cleaner way to do this. I'm thinking... (10 Replies)
Discussion started by: BigCroyd
10 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

sed Command

Hello, I'm working with this command which I'm having trouble understanding it: sed -e '1,$ s/SUB/N/g' < $1 > file.txt Where SUB stand for an special character with code in ASCII is 0x1A, notepad read it as a right arrow. Any help will be appreciated. (5 Replies)
Discussion started by: emilioveras
5 Replies

4. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

5. UNIX for Advanced & Expert Users

sed command

Hi..... I'm using sed command for replace the words in a file cat >test.txt My test.txt contains Mary had a little ham Mary fried a lot of spam Jack ate a Spam sandwich Jill had a lamb spamwich Marry had a spicy wich $ sed 's/wich$/mirchi/g' test.txt output is: Mary had a little ham... (24 Replies)
Discussion started by: ksrivani
24 Replies

6. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

7. Shell Programming and Scripting

Convert Sed command to perl command

Hello, Can any perl experts help me convert my sed string to perl. I am unsuccessful with this. I have to remove this string from html files OAS_AD('Top'); I have come up with this. However the requirement is in perl. for find in $(find . -type f -name "file1.html") ; do cat $find |... (2 Replies)
Discussion started by: abacus
2 Replies

8. UNIX for Dummies Questions & Answers

some help with the sed command please

hi all, attached you can find a small txt file ( .txt ), GIVEN that past_scheduler="islip" and scheduler="mucf" can somebody please tell me WHY sed 's/-u '$past_scheduler'/-u '$scheduler'/g' .txt > .txt.temp fails ? thanx (3 Replies)
Discussion started by: OneDreamCloser
3 Replies

9. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

10. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies
Login or Register to Ask a Question