Skip to main content

All Questions

Tagged with
-1 votes
3 answers
90 views

Delete 2-line paragraphs, keep 3-line paragraphs, maintain newline between all

On a Linux machine with GNU tools I have an ascii file that consists of only 2-line and 3-line paragraphs, each paragraph separated by a newline. All 2-line paragraphs are to be deleted so that all 3-...
stampeder's user avatar
16 votes
5 answers
1k views

How can UserA programmatically replace a text string within a file they own that's located in /etc?

A non-root linux user owns a text file that's located in /etc, where the non-root linux user does not have permission to create files. The non-root linux user can edit the file manually via vi without ...
Tortoise Pirate's user avatar
1 vote
3 answers
73 views

Bash: sum a number present in N lines before a given pattern

I have a kdenlive project file (which is basically a xml file) with a lot of text clips inside. I need to bulk edit the x coordinate of a certain text that appears multiple times. This is an example: ...
baiserekku's user avatar
3 votes
7 answers
434 views

How can I print the longest sequence of lines featuring numbers smaller than a threshold?

I am learning Perl, but I don't know how to solve this problem. I have a .txt file of the following form: 1 16.3346384 2 11.43483 3 1.19819 4 1.1113829 5 1.0953443 6 1.9458343 7 1.345645 8 1....
69 420 1970's user avatar
1 vote
1 answer
51 views

Report sed changes + corresponding perl syntax

Newbie learning Linux and perl: I would like to (a) search-replace strings, (b) match filename pattern .myfile., (c) look recursively in subdirectories, and (d) print the line number, file name, ...
Susie's user avatar
  • 13
1 vote
7 answers
313 views

Find all lines between two patterns, EXCLUSIVE of the second pattern?

Consider that I have the file listed below. I need to select all lines from every instance of the regex pattern Word A to before the regex pattern Word D. Word A Word B Word C Word D Word E Word F ...
RonJohn's user avatar
  • 1,144
-2 votes
3 answers
120 views

bash + how to verify folders under specific path are ended with number/s

I want to check the folder/s under /var/kafka that all them are ended with number otherwhile I will exit with error ls -ltr /var/kafka drwxr-xr-x 399 kafka kafka 28672 Nov 9 13:10 data6 drwxr-xr-x ...
yael's user avatar
  • 13.4k
-1 votes
3 answers
152 views

Replace new lines at end for those lines whose 2nd field in colon separated file span over to multiple line

I have got multiple files with different set of contents but the pattern is same across mulitple lines in different files. sample input file : cat -n test.txt 1 adjfkhjdhfkjd: ...
Ashis Sahoo's user avatar
5 votes
4 answers
697 views

awk add a column if it doesn't exist

I would like to add a column 3 (description) if it does not exist in a ';' delimited file. example; #Gene;Transcripts;Description;Group gene1;G1a,G1b,G1c;gene1 is a good gene;6 gene2;G2a,G2b,G2c;gene2 ...
alex kiarie's user avatar
0 votes
4 answers
658 views

Remove hostnames from URL with sed/awk

I got lists of urls with different domains and I want the hostname removed with sed, awk or something similar and only keep the path. There are no urls with port or username@password in it. input: ...
pwrsheller's user avatar
-1 votes
3 answers
132 views

How to replace the contents of out.txt with in.txt in a third file?

I have three files, main.txt, out.txt and in.txt. I want to replace every occurrence of the contents of out.txt in main.txt with the contents of in.txt. Both out.txt and in.txt may contain multiple ...
Roger Bosman's user avatar
0 votes
2 answers
525 views

Remove multiple occurrences using SED command

We had a requirement to remove all /t characters that are not followed by quotes sed 's/\\t\([^"]\)/foo\1/g' this command worked good for single occurrence. What option do we need to add remove ...
Radhe's user avatar
  • 1
1 vote
2 answers
2k views

How may I replace a string in an XML file?

I am trying to replace the string inside an XML file. From <hello="value" exampleno="xxxx:yyyyyyyy/dd=eeeee-ffffff,aa=bb ccc,dd=eeee,ff=gggg,hh=iii,jj=kkk,ll=mmmm" /> I want ...
Ganesh's user avatar
  • 19
1 vote
6 answers
935 views

Find and replace a multi line text file in another multi line text file

I fought with it for so long but I am now completely out of ideas. Maybe someone here will be able to help me. Here is what I want to achieve: file_1.txt: # Some comment some_variable="test" ...
Peksio's user avatar
  • 121
5 votes
5 answers
780 views

How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?

I have a file that contains multiple IP addresses and hostnames, and another file that contains some folders with many IP addresses per line. ip_hostname.txt host1 10.1.1.1 host2 10.2.2.2 host3 10.3.3....
Outsider's user avatar

15 30 50 per page
1
2 3 4 5
28