VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: Manipulation of content of text file  (Read 1126 times)

R_T_H

  • Member
  • *
  • Posts: 5
Manipulation of content of text file
« on: July 20, 2008, 02: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: 1553
  • I like the bass to go BOOM!
    • Multimedia on VL (work in progress)
Re: Manipulation of content of text file
« Reply #1 on: July 20, 2008, 03: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  :-\. It has a lot of options, you'll want to read
Code: [Select]
man sed
Logged
Most music on my soundcloud page was arranged in programs running on VL.

R_T_H

  • Member
  • *
  • Posts: 5
Re: Manipulation of content of text file
« Reply #2 on: July 20, 2008, 03: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
Re: Manipulation of content of text file
« Reply #3 on: July 20, 2008, 06: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: [Select]
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: [Select]
perl -pe 's/<option value="([^>]*)">.*/$1/' filename >output.txt

HTH

R_T_H

  • Member
  • *
  • Posts: 5
Re: Manipulation of content of text file
« Reply #4 on: July 22, 2008, 02:25:06 am »

Thank you. I'll try that later today.
Logged