Questions tagged [sed]

sed is a command-line stream editor for filtering and transforming text.

Filter by
Sorted by
Tagged with
0 votes
1 answer
28 views

Replace string ${FOO} by ${'$'}{BAR} with sed

I have this string occurring N times in a file: ${FOO} that I have to replace by this string: ${'$'}{BAR} This is my current state: sed "s/\\${FOO}/\\${'\\$'}{BAR}/" file.txt but it raises &...
s.k's user avatar
  • 431
-2 votes
2 answers
55 views

sed inline not working

the problem is that I cannot put the complete command on a line with SED, I had already done it but with those file it does not work: my exemple : <file>Documents/time/text1</file> //2X ...
Allan Tori's user avatar
0 votes
3 answers
87 views

SED command to delete a forward slash "/" between 2 tags

I am using Linux, and I want to use sed to delete a forward slash (/) between 2 tags. From this: <file>/text</file> <file>/text2</file <file>/text</file>.. to this &...
Allan Tori's user avatar
2 votes
1 answer
30 views

Use GNU parallel with very long lines

I have a very large SQL dumpfile (30GB) that I need to edit (do some find/replace) before loading back into the database. Besides having a large size, the file also contains very long lines. Except ...
fernan's user avatar
  • 23
-1 votes
3 answers
78 views

Need help with Sed command with multiple replacements [closed]

I need a file with sed command I have a file like this amb/eng/hello.amb and I need the output to be like below amx/eng/hello.amx amx-grk/eng/hello.amx Could anyone please kindly help me?
afrin's user avatar
  • 61
-2 votes
4 answers
136 views

I need to delete lines when pattern match

I have file on a Linux system, aa.text, which contains the lines below: $ cat aa.text I am a user ORA-1653: unable to extend table SYS.AUD$ by 128 in tablespace SYSTEM [PCRMR2S] Fri Feb 09 23:57:51 ...
ANW's user avatar
  • 7
0 votes
1 answer
60 views

How to add an exact-match flag to the following git + sed function?

I want to create a bash function where you can do a sed find and replace while ignoring the files and folders in .gitignore. I also want to be able to add any git grep flags to the command. For ...
wyc's user avatar
  • 133
1 vote
0 answers
32 views

pfSense (FreeBSD) - tail -f not showing entire log when filtering with cut or sed [duplicate]

I have a strange problem when trying to display logs on pfSense (and I can reproduce the same problem on Ubuntu server also). The problem is this (with examples): I'm trying to display a running dhcp ...
Artur Meinild's user avatar
1 vote
4 answers
92 views

sed command to replace a word within a line following a pattern

I'm working with a file that looks like the following, containing with over 50,000 lines of gene IDs followed by their sequence: gene_A:3342234 CTCTTTCTTTTACGCCT gene_A:1244-5205 CTCTTTCTTTTACGCCT ...
bryophyta's user avatar
0 votes
2 answers
96 views

How to delete rows that contain 0 in the "last column" in a linux terminal?

I'm wondering how can I delete rows when the value in the last column is "0" in multiple .tsv files where the last column number might not be the same for all files. And total number of ...
Debajyoti Kabiraj's user avatar
0 votes
3 answers
80 views

Rename multiple files in directory - Using sed or rename command

I have tried so many different sed, mv and rename commands - still I cannot rename these files. There are 50 plus files - I tried commands I found - Help thx Original filenames: PAGES_TEST1_SART1.XML ...
mattandbeyond's user avatar
2 votes
2 answers
209 views

sed word boundaries: replace command macros with the commands

I inherited a body of code where "command macros" are used in place of the underlying command to be run, e.g., $TR is used in place of tr. I want to use sed to convert the command macros ...
FKEinternet's user avatar
0 votes
3 answers
76 views

sed command gets me error Label too long: on solaris

Given database name oltt206 or DB01 i wish to extract its respective username, password and connection string from the xml below: wladmin@myremhost:/tmp$ cat /web/bea_apps/uat/Tomcat_Home_v9.0.56/...
Ashar's user avatar
  • 491
2 votes
5 answers
409 views

How to split a given column's string values in a text file

I have a text file on a Linux machine with two columns: Column 1 = id_no (most are 5, with some 6 digits long); Column 2 = genetic_markers (all are 50674 digits long); 12345 0102010205 54322 ...
Michiel Van Niekerk's user avatar
0 votes
1 answer
132 views

ERROR : invalid command code ~

I am actually learning about sed command tutorial , where I am running below command in order to print the line 1st,4th,7th,10th,13th ..... line from Notes.txt. I am using MAC terminal sed -n '1~3p' ...
PANKAJ LADE's user avatar
0 votes
0 answers
24 views

Directly Replacing Text in Binary File [duplicate]

I have a compiled executable (binary) file - mybin - which grep indicates contains a positive match with a given text string - Cats. grep "Cats" mybin Binary file mybin matches If I use the ...
Mark's user avatar
  • 101
1 vote
2 answers
51 views

How can I substitute consecutive empty lines with a single one in sed?

I have a file which likes to have consecutive empty lines (more clearly, whitespace-only lines). I want to substitute all of them with a single one. I would prefer sed (this task would be, in awk, ...
peterh's user avatar
  • 9,731
-1 votes
2 answers
47 views

Replace an id by empty character in sql dump

My sqldump is like that LOCK TABLES `mytable` WRITE; /*!40000 ALTER TABLE `mytable` DISABLE KEYS */; INSERT INTO `mytable` VALUES (8118,0,'E4B62B0A-8FFD-4FB9-A7A6-310D0A023426',NULL,'34F1E16B-5095-...
Aukfood's user avatar
0 votes
1 answer
63 views

prepending the matched string in sed

Starting with this input: $ cat file1 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub I can put the fist set of numbers ...
user9101329's user avatar
3 votes
7 answers
422 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
2 votes
3 answers
205 views

Add a tab to the beginning of lines stored in a variable

I am working on a script that will process a .zip file received from clients. It is common in my job to want the contents of the .zip file received listed within a log file as a means of validation. I ...
gritts's user avatar
  • 21
-1 votes
1 answer
83 views

Insert text between two lines

I am trying to insert one line between the below lines auth sufficient pam_unix.so nullok try_first_pass <insert the text here> auth requisite pam_succeed_if.so uid >= ...
Hari's user avatar
  • 1
-1 votes
2 answers
95 views

Grep the word with multiple spaces

I am trying to grep the below text from a file and trying to uncomment the same with sed command. please help #auth required pam_wheel.so use_uid Need to grep and remove # for exact ...
Hari's user avatar
  • 1
0 votes
1 answer
93 views

sed/gsed "invalid command code . ", "expression #1, char 1: unknown command: `.' "

I get these similar errors in both OS X sed and gsed, in a command file that does not contain a period in expression 1, character 1. The only place a '.' appears in the file is on line 5, where it is ...
okto's user avatar
  • 11
2 votes
2 answers
164 views

best / any way to count escapes in glibc regex(7) / GNU sed / grep / egrep Regular Expressions?

Given bash environment variable settings : $ declare -g bs=$'\\' bsbs=$'\\\\' q="'"; This Regular Expression will correctly match a sequence of single quote-("'")-ed text , where ...
JVD's user avatar
  • 115
0 votes
2 answers
129 views

How Delete a Line With sed Without Leaving a Blank Line?

File.txt: line: this-is-some-text line2: this-is-some-other-text Example: sed 's#line:.*##g' File.txt line2: this-is-some-other-text As you can see the first line has been deleted but is left with ...
Nickotine's user avatar
  • 467
0 votes
5 answers
360 views

print characters between a specific pattern containing <>

i am asking for your help please. I reviewed a lot of sources and did some testing with awk and sed, but i can't get it to work. Below is a snippet of a config file which i could get an output via ...
AKSNET's user avatar
  • 13
-1 votes
5 answers
261 views

Delete all lines after n lines below the line containing the first match

If a file contains the following: Line 1 FooLine 5 Line 2 Line 55 Line 3 Line 4 Line 5 Line 6 Line 7 Line 5 Line 8 Line 9 How to delete the lines below two lines after "Line 5", so that the ...
Sadi's user avatar
  • 495
0 votes
1 answer
73 views

Search field and replace other in jq

I am trying to search for an object having a specific property and then update another property. Given this input: [ { "replacements": [ { "newValue": "0&...
Jazzschmidt's user avatar
6 votes
13 answers
1k views

UNIX command to add comma and space

I have a file that looks like $ cat IP 10.3.1.1 10.4.1.1 10.6.3.1 10.19.4.2 10.22.3.4 How do I make it look like: $ cat IP 10.3.1.1, 10.4.1.1, 10.6.3.1, 10.19.4.2, 10.22.3.4
Shahriar Flamneco's user avatar
5 votes
7 answers
1k views

AWK - SED - add a character to the beginning of every column if it starts with a number

How can I add a character to the beginning of every column that starts with a number: Example adding a c to: 4 r4 8 8 4 So I get this output: c4 r4 c8 c8 c4 It should work for a variable number of ...
nath's user avatar
  • 5,620
0 votes
2 answers
73 views

Confusing results of eval + sed combination [closed]

I run a game from steam which starts with the game companies launcher app where I have to click another button to start the actual game. The game launcher is very slow, contains needless advertising, ...
nobody special's user avatar
1 vote
1 answer
60 views

Sed - replace a string with a character of another line

I am trying to write a script to reformat some text. pages: page1: gui-rows: 6 items: '6': material: CAT_SPAWN_EGG buy: 999999999 sell: -1 '7': ...
Pegoku's user avatar
  • 11
0 votes
2 answers
125 views

Sed - How to replace two strings, but preserving what is in between them?

I am writing a shell script to convert some DokuWiki pages to MediaWiki format and vice versa. I'm having some troubles with footnotes. There is a plugin for DokuWiki that adds extended features to ...
Daniel's user avatar
  • 353
5 votes
4 answers
386 views

Replace single quote at beginning of columns

I receive input files that are outside my control that contain a leading single quote in some columns, such as 'foo|'012|that's nice|bar I want to remove all leading single quotes from each field, to ...
enharmonic's user avatar
0 votes
4 answers
102 views

Copy matching lines to the next line and modify?

Given a file like this: a foo 1 b bar 2 c foo 3 d baz 4 e bar 5 I want to modify that file as follows: copy every line containing bar to the following line and change bar to bar2, so that the result ...
Nathan Long's user avatar
  • 1,613
1 vote
1 answer
45 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
0 votes
1 answer
95 views

shell one-liners for bulk-renaming multiple files

I am looking for two renaming one-liners to manage my music library. First concerns filenames. I would like to use as simple as possible names, that is : %track %title.ext for instance 01 Song name....
sylvainsab's user avatar
0 votes
1 answer
88 views

Whats the meaning of this sed command sed '/^[[:space:]]*$/d'

I came across this sed command in a script to compare a machine's local binaries to GTFObins binaries. for i in $(curl -s https://gtfobins.github.io/ | html2text | cut -d" " -f1 | sed '/^...
M4raa's user avatar
  • 3
0 votes
1 answer
64 views

tail -f, multi sed [duplicate]

I can do tail -vf -c5 thefile \ | cat -n \ | sed -E 's/a/b/g' \ ; But the following gives no output. tail -vf -c5 thefile \ | cat -n \ | sed -E '...
john-jones's user avatar
  • 1,664
2 votes
2 answers
339 views

Tail -f | sed. Modify text for color

I am modifying the text following tail -f. I have the following program that monitors a file: tail -vf -c5 /tmp/index \ | cat -n \ | ...
john-jones's user avatar
  • 1,664
1 vote
7 answers
284 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,138
0 votes
5 answers
215 views

Delete lines below, excluding the line with match pattern

One can use sed '/pattern/Q' or sed '/pattern/,$d' to delete lines below a match pattern, but it also deletes the line containing the match pattern. How to exclude the line containing the match ...
Sadi's user avatar
  • 495
0 votes
6 answers
256 views

Delete all lines before n lines above the line containing the first match

If a file contains the following: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 How to delete the lines above two lines before "Line 5", so that the file will now contain ...
Sadi's user avatar
  • 495
-1 votes
2 answers
115 views

Grep a log file for SQL queries and their execution time

I have an application log file that also captures the execution time for each executed SQL statement, like below:- Sample logs: I 2023-11-15 07:18:00.743Z 1760463 37 ZVRwqItu6aw-b8eejMLI_gAAAAU 1@...
Arpit Jain's user avatar
-2 votes
4 answers
216 views

Print everything before nth delimiter

I'm looking for a sed solution like the one here: Print everything after nth delimiter sed -E 's/^([^\]*[\]){3}//' infile but to extract the text before nth delimiter, instead of nth delimiter like ...
Smeterlink's user avatar
-2 votes
3 answers
119 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.1k
2 votes
1 answer
177 views

Escape special characters from variables [duplicate]

I have #!/usr/bin/bash search="ldo_vrf18 {" replace="$search"' compatible = "regulator-fixed"; regulator-name = "vrf18&...
Bret Joseph's user avatar
0 votes
1 answer
74 views

Using Sed to modify php memory limit

I am writing a script that needs to modify the default php_admin_value[memory_limit] from 128 M to 512M. I don't get any errors when i execute the command from the CLI or from a bash script, but ...
n8dagr8's user avatar
1 vote
5 answers
125 views

How might I swap the remaining parts of lines (with the exception of first characters) with sed?

I have a file, fr.fc that represents flashcards used by hardv that I want to use to generate with sed a similar file, fr-swapped.fc %% This is a card set for hardv(1) %% Created at Feb 1, 1997 NEXT ...
John Smith's user avatar

1
2 3 4 5
146