1
vote
2answers
46 views

replace file's content between specific line numbers with another file using BASH

What is the most efficient way to replace file's content between specific line numbers with another file? Here is a sample: main.txt: a b c d e f g h i j k l new.part.txt x y z p q r s t u The ...
1
vote
1answer
83 views

Shell: how write multiline text file without escaping special symbols?

I know the question sounds to be discussed thousands times before. But somehow I can't find good solution. Problem: I need to write multiline text from shell. The text might contain special chars ...
7
votes
3answers
4k views

grep for “term” and exclude “another term”

I am trying to build a grep search that searches for a term but exludes lines which have a second term. I wanted to use multiple -e "pattern" options but that has not worked. Here is an example of a ...
2
votes
1answer
74 views

Substitute large numbers of files according to style guide

I'd like to do a wholesale reformatting of our tests, and I'm cleaning up some inconsistent capitalization. I'm thinking of using awk to do this, since sed falls a little short, and since I need ...
11
votes
3answers
2k views

Substitution in text file **without** regular expressions

I need to substitute some text inside a text file with a replacement. Usually I would do something like sed -i 's/text/replacement/g' path/to/the/file The problem is that both text and replacement ...
1
vote
1answer
410 views

Copy files from m3u to destination

I have a playlist, m3u extended, formated like: #EXTM3U #EXTINF:213,2 Tåst - (foo bar) /home/www/Music/Test/test 123 - test.mp3 My problem is, that it seems the line-break is encoded as '\n\r' ...
0
votes
2answers
224 views

Efficiently stripe incoming one-word lines onto columns?

Consider a stream of one-word lines such as the stdout of $ echo foo bar baz quux xyxxy thud | tr ' ' '\n' foo bar baz quux xyxxy thud I say "one-word" to indicate there is no whitespace other than ...
0
votes
1answer
2k views

Sed error “sed: -e expression #1, char [#]: extra characters after command”

sed '/\r$/ {N s/\n//}' sed: -e expression #1, char 10: extra characters after command I want to understand what is wrong with my command line. When I can do the some of following in a script ...
2
votes
1answer
259 views

Adding custom rows to file using a shell script

I have a textfile with an arbitrary number of rows triplets like these: 4 5 2 12 16 6 Now I want to add related rows to the file. Let's say i want to add 4 additional rows per row which have ...
1
vote
2answers
320 views

How to show regexp parts of text

I've lots of files which lines looks like lotsofblah/XY##_####_morefoo where # is a number. Now i want to show only the parts YZ##_#### in the bash, each in a new line of course.
11
votes
5answers
18k views

How to replace multiple spaces by one tab

I've some text files which contain some colums seperated by a various number of spaces, but instead I need one single tab as a seperator. Is it possible to do in Bash?
6
votes
3answers
532 views

Substract contents of one textfile from contents of another textfile on Linux

I have two text files on Linux. One contains a list of valid IDs. E.g: abcd efgh ijkl etc. The other contains a list of invalid IDs. But, some of these also appear on the list of valid IDs, in this ...
1
vote
4answers
279 views

retrieving headers / comment blocks

I have a number of log files that look like this: /* header arbitrary number of lines */ blah blah blah blah Using simple Bash commands (preferably sed, not awk), how would I retrieve only the ...