Questions tagged [text-manipulation]

Text/String manipulation is the term used to describe various operations applied to strings and/or text.

Text/String manipulation is the term used to describe various operations applied to strings and/or text. Often used with Regex or replace functions, concatination, etc.

237 questions
66
votes
7 answers

How to split strings on carriage return with C#?

I have an ASP.NET page with a multiline textbox called txbUserName. Then I paste into the textbox 3 names and they are vertically aligned: Jason Ammy Karen I want to be able to somehow take the names and split them into separate strings whenever i…
Erica
  • 675
  • 1
  • 5
  • 4
51
votes
6 answers

excluding first and last lines from sed /START/,/END/

Consider the input: =sec1= some-line some-other-line foo bar=baz =sec2= c=baz If I wish to process only =sec1= I can for example comment out the section by: sed -e '/=sec1=/,/=[a-z]*=/s:^:#:' < input ... well, almost. This will comment the lines…
Chen Levy
  • 15,438
  • 17
  • 74
  • 92
33
votes
8 answers

How to get Git log with short stat in one line?

Following command outputs following lines of text on console git log --pretty=format:"%h;%ai;%s" --shortstat ed6e0ab;2014-01-07 16:32:39 +0530;Foo 3 files changed, 14 insertions(+), 13 deletions(-) cdfbb10;2014-01-07 14:59:48 +0530;Bar 1 file…
Ankush
  • 2,454
  • 2
  • 21
  • 27
29
votes
7 answers

How to extract two consecutive digits from a text field in MySQL?

I have a MySQL database and I have a query as: SELECT `id`, `originaltext` FROM `source` WHERE `originaltext` regexp '[0-9][0-9]' This detects all originaltexts which have numbers with 2 digits in it. I need MySQL to return those numbers as a…
Steve
  • 1,857
  • 5
  • 32
  • 45
17
votes
4 answers

Shift a region or line in emacs

I'm looking for a way in emacs to shift text to the right or to the left by n spaces. A similar functionality that it in vim << or >>. It should work on a region or if no region is selected on a current line and not move the cursor from its current…
fikovnik
  • 3,473
  • 3
  • 28
  • 29
16
votes
4 answers

Java regex: newline + white space

should be simple, but I'm going crazy with it. Given a text like: line number 1 line number 2 line number 2A line number 3 line number 3A line number 3B line number 4 I need the Java regex that deletes the line terminators then the new line…
MatteoSp
  • 2,940
  • 5
  • 28
  • 36
15
votes
2 answers

Edit configuration file through python

I need to edit a configuration file through python and i tried searching on stackoverflow and google and they don't cover my situation, since i need to replace lines in the file and perform matches in my search. Also, what i found covers how to do…
14
votes
3 answers

sed - comment a matching line and x lines after it

I need help with using sed to comment a matching lines and 4 lines which follows it. in a text file. my text file is like…
Sanjan Grero
  • 317
  • 3
  • 5
  • 11
12
votes
5 answers

PHP Repairing Bad Text

This is something I'm working on and I'd like input from the intelligent people here on StackOverflow. What I'm attempting is a function to repair text based on combining various bad versions of the same text page. Basically this can be used to…
Alasdair
  • 13,348
  • 18
  • 82
  • 138
12
votes
9 answers

Insert multiple lines of text before specific line using Bash

I am trying to insert a few lines of text before a specific line, but keep getting sed errors when I try to add a new line character. My command looks like: sed -r -i '/Line to insert after/ i Line one to insert \\ second new line to insert \\ …
MeanwhileInHell
  • 6,780
  • 17
  • 57
  • 106
12
votes
2 answers

Using str_word_count for UTF8 texts

I have this text: $text = "Başka, küskün otomobil kaçtı buraya küskün otomobil neden kaçtı kaçtı buraya, oraya KISMEN @here #there J.J.Johanson hep. Danny:Where is mom? I don't know! Café est weiß for 2 €uros. My 2nd…
trante
  • 33,518
  • 47
  • 192
  • 272
11
votes
4 answers

How to split file on first empty line in a portable way in shell (e.g. using sed)?

I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into two on first empty line (or for UNIX tools on first line containing only CR…
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
10
votes
2 answers

How to find words from one file in another file?

In one text file, I have 150 words. I have another text file, which has about 100,000 lines. How can I check for each of the words belonging to the first file whether it is in the second or not? I thought about using grep, but I could not find out…
ocslegna
  • 113
  • 1
  • 2
  • 9
8
votes
6 answers

Obfuscating email in html

I'm currently developing a website, into which I've included a filter that attempts to obfuscate any e-mail addresses present in the webpages it serves. As it is now, it converts the addresses into images. I've also seen a few other methods in use;…
nikc.org
  • 16,462
  • 6
  • 50
  • 83
6
votes
2 answers

How to extract part of a Base64 encoded string in MySQL?

I have a field in my database which is encoded. After using from_base64 on the field it looks like this: /////2017//06//21////file.txt There may be an undetermined number of strings at the beginning of the path,…
1
2 3
15 16