script to convert words into links


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to convert words into links
# 1  
Old 08-03-2008
script to convert words into links

hi,

i need some help.
i have to write a unix shell script that opens a file with a list of words and prints another file with a list of links.
something like this:

Input:

FILE 1:
Red
Green
Blue

Output:

FILE2:
http://www.google.com/search?hl=en&q=Red
http://www.google.com/search?hl=en&q=Green
http://www.google.com/search?hl=en&q=Blue]Blue

How would you do this ?

Last edited by kazordoon; 08-03-2008 at 10:31 AM..
# 2  
Old 08-03-2008
A solution with sed :
Code:
sed 's§^§http://www.google.com/search?hl=en&q=§' FILE1 > FIL2

Jean-Pierre.
# 3  
Old 08-03-2008
Code:
sed 's%^%http://www.google.com/search?q=%'

I don't think you need the hl=en parameter.

PS. Might be better to use code tags for raw http links.

Jean-Pierre's solution has the problem that the & needs to be backslash-escaped. Seems we posted at exactly the same time.

Last edited by era; 08-03-2008 at 10:30 AM.. Reason: Note identical posting by aigles
# 4  
Old 08-03-2008
A solution with awk :
Code:
awk '{printf "http://www.google.com/search?hl=en&q="}1' words_file > links_file

# 5  
Old 08-03-2008
thank you.

that would be the core of the script , but how would you put the loop to read the words one by one and print them out in the other file ?
# 6  
Old 08-03-2008
Quote:
Originally Posted by era
[CODE]Jean-Pierre's solution has the problem that the & needs to be backslash-escaped.
Smilie Good shot
Code:
sed 's§^§http://www.google.com/search?hl=en&q=\§' FILE1 > FIL2



Jean-Pierre.
# 7  
Old 08-03-2008
thanks. i tried and it works Smilie

forget my last message about the loop, i saw that your line is enough for doing what i need. thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Shell script to convert words to Title case

Hi :) I have a .txt file with thousands of words. I was wondering if i could use a simple sed or awk command to convert / replace all words in the text file to Title Case format ? Example: from: this is line one this is line two this is line three to desired output: This Is Line... (8 Replies)
Discussion started by: martinsmith
8 Replies

2. AIX

List all the soft links and hard links

Hi I'm logged in as root in an aix box Which command will list all the soft links and hard links present in the server ? (2 Replies)
Discussion started by: newtoaixos
2 Replies

3. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

4. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

5. Shell Programming and Scripting

How to change symbolic links via script

Hello, the install routine puts automatically the servername "SERVER" in the symlink like: hello.txt --> /SERVER/usr/lpp/hello.txt world.txt --> /SERVER/usr/lpp/world.txt ... but i need to change this symlinks (without servername) to: hello.txt --> /usr/lpp/hello.txt world.txt -->... (3 Replies)
Discussion started by: smitty11
3 Replies

6. Shell Programming and Scripting

Symbolic Links - BASH Script

Hi all, This is my first message in this forum. I'd like to know if there is a nice way to get the complete path from a symbolic link. Example: When I do a ls -ltr I see this output. lrwxr-xr-x 1 mmmm users 66 Sep 4 09:58 LINK_SEND ->... (4 Replies)
Discussion started by: rodrimuino
4 Replies

7. Shell Programming and Scripting

here-doc convert 2 script convert to single script?

I have my main script calling another script to retrive a "ls -alt" of a directory that's located in a remote location I'm sftping into. main.sh #!/bin/ksh getLS.sh > output.txt getLS.sh #!/bin/sh /home<..>/sftp <host@ip> <<! cd /some/dir/Log ls -alt quit ! Basically I'd like to be... (2 Replies)
Discussion started by: yongho
2 Replies

8. Shell Programming and Scripting

Need Help : Links to Shell Script Tutorials

Hi, I am very new to shell scripting. Appreciate if you suggest some good & concise online book(s)/tutorial(s) to start with. Thanks in advance. Kotha. (3 Replies)
Discussion started by: kotha
3 Replies
Login or Register to Ask a Question