VectorLinux
July 28, 2014, 12:06:29 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: Manipulation of content of text file  (Read 1005 times)
R_T_H
Member
*
Posts: 5


« on: July 20, 2008, 01:18:05 am »

Is there any way to manipulate text files to delete/replace certain strings of characters? I ask this because I want to be able to read the archive of a webcomic whilst on holiday. Consequently, I went to the archive page and from the source I got the option box. After "sort"ing and "uniq"ing with < >, I now have a text file that consists only of data in the form:

Quote
<option value="[link]">[name]</option>

Is there any way to remove everything except the link, i.e. so that it deletes:

Quote
<option value="">[name]</option>

Or could it be done by copying [link] to another file?

Reuben
Logged
The Headacher
Louder than you
Global Moderator
Vectorian
*****
Posts: 1545


I like the bass to go BOOM!


WWW
« Reply #1 on: July 20, 2008, 02:05:40 am »

What you need, is probably sed:
Quote from: man sed
Sed  is  a  stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).

I'm just not sure how  Undecided. It has a lot of options, you'll want to read
Code:
man sed
Logged

Most music on my soundcloud page was arranged in programs running on VL.
R_T_H
Member
*
Posts: 5


« Reply #2 on: July 20, 2008, 02:18:07 am »

Hmmm... Yes, I was looking at this on Linux command.org. I'll look at it in more detail. Thank you.
Logged
kidd
Packager
Vectorian
****
Posts: 682


« Reply #3 on: July 20, 2008, 05:12:49 am »

as The Headacher said, sed is the classic tool to do it, although you could probably do a perl oneliner and would be somewhat easier, due to perl regexps being more advanced and clearer than sed's

Code:
perl -pi -e 's/<option value="([^>]*)">.*/$1/' filename

This will write the results to the same file, if you want to write the results on another file,

Code:
perl -pe 's/<option value="([^>]*)">.*/$1/' filename >output.txt

HTH
Logged

R_T_H
Member
*
Posts: 5


« Reply #4 on: July 22, 2008, 01:25:06 am »

Thank you. I'll try that later today.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!