Skip to main content

Questions tagged [sed]

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

Filter by
Sorted by
Tagged with
-1 votes
3 answers
89 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
1 vote
2 answers
60 views

Use sed to insert a character in an xml file

I have an xml file with content following this format: <type:color>000000</type:color> <type:color>FFFFFF</type:color> The information within the tags are hex colors (many ...
jon danniken's user avatar
2 votes
2 answers
852 views

What does '\($*\)' mean in sed regular expression in a makefile?

I encounter the following sed command in make's manual. sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' And it has the following effect (this is an example in the manual): main.o : main.c defs.h # is turned into:...
liginity's user avatar
  • 143
1 vote
2 answers
58 views

Need to make multiple multiline replacements in file

I have a file with multiple "paragraphs" like this: <type>TRANS</type> <attributes/> <specification_method>rep_name</specification_method> <trans_object_id/&...
Todd Porter's user avatar
2 votes
4 answers
140 views

Sed command listing all lines between pattern including the final line

I have a file similar to below. [object_category=file] filesystem = enabled [object_category=registry] registry = enabled [privilege_id=SeAuditPrivilege] audit = enabled [privilege_id=...
ranjit abraham's user avatar
0 votes
3 answers
34 views

Convert timestamp to new format using SED

I have a giant .md file with a series of entries that represent the date like so: [2024/06/10 10:03 PM] However, I need to alter all of these so they now appear like so: 20240610. Thinking through ...
Linter's user avatar
  • 159
0 votes
0 answers
56 views

cleaning up full directories at once

right now, i have a filesystem that fills up fairly regularly. the TL;DR is that I can't introduce better log rotation, and the files must be deleted regularly. let's say i have the following output ...
Britton Harsch's user avatar
3 votes
4 answers
561 views

Cut and replace Nth character on every row

I have predictable piped input, I want to iterate over each row and change two characters. the character positions are 19 and 20 (on every row.) The 19th character is a comma, I want to cut that. The ...
XJMZX's user avatar
  • 75
-2 votes
1 answer
61 views

regular single column data to multiple rows

source data KKK-SNMImsi: 444444 KKK-SNMUserProfileId: KKK-SNMDefaultAutomaticProfile KKK-SNMMmeAddress: TDSGSN01 KKK-SNMMsisdn: 44235682436 KKK-SNMLocationState: LOCATED KKK-SNMRoamingAllowed: FALSE ...
Peter Cherop'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
2 votes
1 answer
87 views

Proxy between UNIX socket with socat

I used socal to create a proxy server between 2 UNIX sockets: /var/a.sock , /var/b.sock client -> /var/a.sock -> MY_COMMAND -> /var/b.sock -> MY_COMMAND -> /var/a.sock ->client. The ...
Polo1990'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
2 votes
2 answers
90 views

sed in conjuction with xargs and grep not working

I'm trying to change a string in multiple text files (configurations migrated to other user). I used this command: grep -iIlr "/home/user/.local" | xargs sed -i 's/\/home\/user\/\.local/~\/\....
Krackout's user avatar
  • 2,742
0 votes
3 answers
81 views

Extract YouTube video IDs from the end of filenames

I downloaded some files from YouTube a while back with the YouTube IDs in their names. My problem is that some IDs contain a character that also marks the beginning of the ID itself. $ ls *.mp4 | head ...
Joshua Briefman's user avatar
0 votes
3 answers
95 views

Using sed or awk, how can i delete a line whenever the next line begins with the same content followed by a slash?

Using sed or awk, how can I delete a line whenever the next line begins with the same content followed by a slash?
Paul Midgette's user avatar
-1 votes
2 answers
96 views

How to diff two files in bash efficiently?

I have two files containing the similar pattern: cmd1 [cmd2 {xx/xx[7] x/x[0] ...}] cmd3 [cmd4 {xx/x[12] ...}] cmd5 [cmd6 {x/x[1] xx ...}] I don't need to consider all the cmds in two files. Only need ...
Alan Gatsby's user avatar
0 votes
2 answers
50 views

How can I only execute sed commands after so many pattern matches in macOS?

I have a file that contains the same pattern multiple times. I am trying to get sed to perform a series of operations only for the second occurrence of that pattern. The file looks like this: pattern ...
Felipe Evaristo's user avatar
0 votes
1 answer
56 views

Strip a line from a variable using awk or sed

There is a Zsh variable with contents like $if(description-meta)$ <meta name="description" content="$description-meta$" /> $endif$ <title>$if(title-prefix)$$title-...
jsx97's user avatar
  • 71
1 vote
1 answer
126 views

Why is sorted uniq -c command showing duplicates

I am trying to count how many times I use a certain version of a library on my computer. For some reason, uniq -c is outputing duplicates, despite sorting it, and despite the sort order seeming in ...
Albert's user avatar
  • 161
-2 votes
1 answer
61 views

Parse txt file on basis of occurrence of a tag in Linux

I am trying to parse a txt file containing xml "messages"in linux, something like this <Document abc xyz .....> <hji> xyz </hji> </Document> <Document abc xyz ........
python6's user avatar
-1 votes
2 answers
108 views

how to de-duplicate block (timestamp+command) from bash history?

I'm working with bash_history file containing blocks with the following format: #unixtimestamp\ncommand\n here's sample of the bash_history file: #1713308636 cat > ./initramfs/init << "...
Yuki San's user avatar
4 votes
4 answers
228 views

how to replace the last n occurences of string using sed

I can replace the third occurrence of a string with: sed 's/OLD/NEW/3' or, with the GNU implementation of sed, all occurrences starting from the third with: sed 's/OLD/NEW/3g' But how do I replace ...
user167612's user avatar
  • 1,700
1 vote
2 answers
28 views

change newline with space on certain condition with sed

I have the following text in a file: #1713251479 sh lowbat.sh #1713251495 nvim lowbat.sh #1713252186 sh lowbat.sh and I want to put the Unix timestamp inline with the command like this: #1713251479 ...
Yuki San's user avatar
0 votes
1 answer
48 views

Add \t to jq resulted array extraction

I want to add \t before each element in the resulting jq array and this is for formatting purposes as the result will get added to a file. here is the json file: { "array": ["...
kyles's user avatar
  • 33
-1 votes
1 answer
38 views

sed and tr not replacing mystery control character

root@calleva:~# echo "f" > file root@calleva:~# f=$(<file) root@calleva:~# echo "$f" f root@calleva:~# echo "$f" | tr -c '[:alpha:]' '_' f_root@calleva:~# echo &...
Richard Barraclough's user avatar
0 votes
5 answers
89 views

How can I replace the last occurrence of " before ] (text-manipulation)

I'm doing some text manipulation and I want to replace the last occurrence of " (with ", "four") before ] which could be in different lines. (this essentially adds a new item in ...
kyles's user avatar
  • 33
3 votes
5 answers
165 views

How to remove double quotes within the double-quoted field values in .dat file

I have a text file that has around 15 columns.  The fields are separated by comma.  One column that is description is double-quoted and also has some words which are double-quoted.  I need to retain ...
Mythri's user avatar
  • 43
1 vote
3 answers
70 views

How can I add a property in the end of the object (text manipulation)

I'm doing some text manipulation and I want to add a property (at the end) to an object named "object" that is inside a configuration file e.g . . object = { "one": "one&...
kyles's user avatar
  • 33
0 votes
1 answer
47 views

Regex pattern in sed to match hexadecimal address of fixed length [duplicate]

I would like to match a hexadecimal address of fixed length using a regex pattern in sed. For example: 0x000000010b2e993c 0x is always present followed by the sixteen-character hexadecimal number. ...
Max MacLeod's user avatar
0 votes
2 answers
66 views

extract a column from the command output even if it blank bash

I am trying to extract 2nd column from a command output For example: $ sudo /usr/sbin/pvs PV VG Fmt Attr PSize PFree /dev/sdc1 vgswap lvm2 a-- 16.00g 0 /dev/sdc2 ...
Vija200's user avatar
0 votes
3 answers
89 views

regex in grep vs sed

I am trying to find and replace all lines in a text file that start with a single space and then any characters. Finally got the regex to work on grep grep -E '^ .*$*' Contacts.vcf >> t.txt Then ...
atclaus's user avatar
  • 101
1 vote
2 answers
81 views

extract string before numbers and after underscore

The original string is like this: str-str001-002_01 str-str005-006_05 I would like to extract string before number, and after underscore, so it would be like this: str-str_01 str-str_05 I remember ...
Tiina's user avatar
  • 157
-1 votes
1 answer
57 views

Problem with a command into Sed

This following code should outputs theString LANG=C ; echo 'aString12 theString34 otherString56' | \ sed "s;aString12 \(theString34\) anotherString56;$(printf '%s' "\1" | sed 's;[0-9]\{...
Mark's user avatar
  • 1
1 vote
1 answer
61 views

How can I include any content in the sed replace command? [duplicate]

I want to be able to handle any type of content stored into the bash variable ${CONTENT}, to be used as sed replacement text into another content, no matter if there are quotation marks, single quotes ...
Harry McKenzie's user avatar
-1 votes
2 answers
61 views

How to replace (***) with \(***\) with sed

so I wanted to write a script to replace special characters with their escaped equivalent so I can pass it to mkdir command. As a friend used a similar line I can use this to replace parantheses with ...
Navid Taghavi's user avatar
0 votes
0 answers
21 views

Non-column output of `ls` piped to `sed` [duplicate]

As far as I know, command sed precesses its input line by line. Thus, the following command successfully outputs only the directories in the current directory: $ ls -p -1 | sed -n '/\/$/p' Here ...
gambarimas87's user avatar
1 vote
1 answer
37 views

Strange behavior with sed/head and named pipes/FIFOs (needs two writes)

I have a fifo created with mkfifo in a shell, opened in rw mode with exec 3<>fifo. When I run sed 1q <&3 and write a line to the fifo in another shell, sed doesn't print the line until I ...
SeetheMoar's user avatar
3 votes
5 answers
238 views

How to let sed un-comment one of multiple paragraphs separated by newlines?

Clarification: Using GNU sed. Status quo - ~/.screenrc, last lines: # name synthpop # screen -t script emacs -nw /home/$USER/bin/synthpop # name thrashmetal # screen -t script emacs -nw /home/$USER/...
futurewave's user avatar
-1 votes
5 answers
71 views

multiline grep search into separate files per occurence

I have a file as following: example.txt -1 15 1 0 0 11 -1.0000E+001 1.0000E+001 -1.0000E+001 2 0 0 11 1.0000E+001 1.0000E+001 ...
Honza S.'s user avatar
  • 101
1 vote
3 answers
103 views

sed to replace in a file, with both old and new strings in files

I want to automatically comment out a code block in PHP file, as below: The original block: // Enable all errors ini_set('display_startup_errors', 1); ini_set('display_errors', 1); ...
alancc's user avatar
  • 213
0 votes
3 answers
121 views

Remove all lines between two similar patterns if a specific pattern in between is not matched

The title should be: Remove all lines between two similar patterns, including the line of the starting pattern. if another specific pattern in between is not matched. I made it shorter because its ...
pwrsheller's user avatar
0 votes
1 answer
22 views

Using sed to filter output of rsync --itemize-changes -i [duplicate]

After using rsync --itemize-changes -i --recursive --checksum --dry-run to compare the contents of two drives, I got this kind of result: 2024/03/12 08:31:01 [15248] .d Backups/Phone/Pictures/...
the_redburn's user avatar
2 votes
2 answers
106 views

Search and replace composed Unicode characters

I have a deep folder structure on a Debian machine where the directory names and the filenames contain some "special" characters (ä,ö,ü).  However, these are not in "ISO-8859-1" ...
rockZ's user avatar
  • 769
1 vote
4 answers
177 views

Use sed or grep in bash script to check if file ends with specific string

I have a file called output.txt on my ubuntu server, how do I use sed or grep to check if the last two characters in the file are "nt" The text in the file is below, I expect my if statement ...
user23376904's user avatar
0 votes
5 answers
160 views

How to add content to a file before the last } character using Busybox utilities?

There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { ...
Maxim's user avatar
  • 119
0 votes
1 answer
43 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
  • 471
-1 votes
3 answers
109 views

sed inline not working to modify XML-style input

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
2 votes
4 answers
151 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
52 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
88 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

1
2 3 4 5
147