Go Back   CodingForums.com > :: Computing & Sciences > Computer/PC discussions

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-24-2012, 05:13 PM   PM User | #1
kentmc
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kentmc is an unknown quantity at this point
Online tool for repetitive text operations

Hi guys, I just wanted to hear you opinion on this topic.
I recently needed to convert a long list looking like this:
---
1
2
3
---
to this format:
---
["1",
"2",
"3"]
---
I could not find anything from a quick Google search that would help me except for programs that needed to be downloaded. I decided to make an online tool for doing different kind of text operations.
You can check it out at http://www.textmacro.com
I would like to know if I am the only one who has needed such a tool or if you know about other existing tools?
kentmc is offline   Reply With Quote
Old 12-05-2012, 03:21 PM   PM User | #2
stevenmw
Regular Coder

 
stevenmw's Avatar
 
Join Date: Jun 2007
Location: OK
Posts: 446
Thanks: 26
Thanked 30 Times in 30 Posts
stevenmw is an unknown quantity at this point
I use my Linux terminal to do it. I simply use grep to find things in files, and then I use sed to go through the file and replace whatever I want.

Say I have a ton of PHP files, and I wanted to find a single word or sequence of words.
grep -r -i -l "keyword" *.php

The * is a wild card. It represents what to look for. It my example it looks for anything ending with .php You can put things before the * and it will look for anything starting with what you specify and ending in anything One example would be hidden files. Hidden files start with a period so I could do.

grep -r -i -l "keyword" .*

-r recursive (will search folder and subfolders)
-i case insensitive (ignores UPPERCASE or lowercase)
-l list only (displays names of files found only)


to find and replace
grep -rl 'this' /some_directory/ | xargs sed -i 's/this/that/g'

The above line would replace all instances of 'this' with 'that'


This is one huge reason I really like Linux. There are so many regex options to use with the grep and sed commands.

You can replace all lower case instance to upper case, replaces spaces with underscores, etc. All using one line.

You can build long complicated regexes to do all kinds of things.
__________________
--
Thanks!

Last edited by stevenmw; 12-05-2012 at 03:26 PM..
stevenmw is offline   Reply With Quote
Old 12-12-2012, 11:53 AM   PM User | #3
sunitisood16
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sunitisood16 is an unknown quantity at this point
I think pHP code wil help you out for the purpose. Best to discuss with a programmer (dot net,Php) he will guide you.
sunitisood16 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:52 AM.


Advertisement
Log in to turn off these ads.