Questions tagged [sed]
sed is a command line editor for POSIX environments. It processes one or more files according to an editing script and writes the results to standard output. Created at Bell Labs, it has been around since the mid-70s.
27,237
questions
0
votes
2
answers
40
views
Delete any special character using Sed
I have yet another list of subdomain. I want to remove any Wildcard subdomain which include these special characters:
()!&$#*+?
Mostly, the data are prefixly random. Also, could be middle. Here's ...
-3
votes
2
answers
46
views
sed command with dynamic variable and spaces - not retaining spaces
I am trying to insert a variable value into file from Jenkinsfile using shell script in the section
Variable value is dynamic. I am using sed.
Sed is working fine but it is not retaining the white ...
0
votes
2
answers
28
views
sed and special characters inside a variable (macOS Monterey)
I'm new to shell scripting and Terminal usage.
I have the follow line of code in a zsh script, where the PATH_VAR is always an absolute folder path that I have to insert:
#!/bin/zsh
...
read PATH_VAR
...
0
votes
1
answer
26
views
sed regex pre-append not working with a different input
I have the following sed replace, which works correctly
$ echo "1.1.1.1\n2.2.2.2" | sed "s/^/allow /g; s/$/;/g"
allow 1.1.1.1;
allow 2.2.2.2;
However, when I run the same regex ...
0
votes
1
answer
26
views
Remotely changing a chrome config file on a raspbian system via MacOS' ssh
Long time listener (and a massive fan, this platform has me gotten out of predicaments more times that I can count), first time writer:
I am looking after a project where we run several Raspbian ...
-1
votes
0
answers
11
views
Use sed for replace special character [duplicate]
Hello i try to use sed for replace special character.
In fact i want to use sed for replace ClusterApiUrl("devnet") to http://127.0.0.1
I try:
sed -i "s/ClusterApiUrl("devnet")...
-5
votes
1
answer
39
views
How to compare if 2 successive lines from a file have matching pattern using awk script? [closed]
Wish to compare for first 4 matching words of successive lines while reading a text file. If they match join the 2 lines. Same for the next line and so on.
eg:
Sample text file:
I will party today ...
0
votes
1
answer
20
views
regex nagative assert does not work in Linux 'find' command with regextype being 'sed'
Say I want to match files where the second digit doesn't equal 0.
e.g.
./update110000.pt -> match
./update170000.pt -> match
./update100000.pt -> not match
so I wrote this
.*update[0-9](?!0)[...
0
votes
1
answer
38
views
Find the second word delimited by space or comma then insert strings before and after
I have a file containing TABLE schema.table and want to put strings around it to make a command like MARK string REJECT
the file contains many lines
TABLE SCHEMA.MYTAB, etc. etc....
or
TABLE SCHEMA....
1
vote
2
answers
59
views
How to print fields containing specific substrings with awk?
Goal: To print fields from an input file to an output file, but with special regard to specific fields split by semicolons (; — see field nine of example input below).
Example Input (input.txt):
...
1
vote
4
answers
72
views
File Formatting with sed
I've been trying to manipulate a single line in a file without much success.
test.txt
10.20.30.40 "User 1"
73.15.16.24 NewUser
124.18.21.17 "User 2"
27.76.58.248 "User 3"...
0
votes
7
answers
70
views
sed command to add a line after some pattern
I have a file (content below)
name = [
"victor",
"linda",
"harris",
"sandy"
]
Now how to i add a command (shell using sed or awk) and i need ...
0
votes
1
answer
49
views
Awk replace specific value from another file only if key match
I want to compare 2 files and have the 1st column of File1 and the 2nd column of File2 to be the keys in the array. Then if those match I want the 3rd column of File2 to replace the 3rd column of ...
-1
votes
1
answer
29
views
Filter the output of powercli command to only had a part of it
The output of the command is:
PS /root> Get-VM -Name alex-deploy2-000638 | Get-Harddisk
CapacityGB Persistence Filename
---------- -----...
-1
votes
1
answer
25
views
Why is "sed s/REGEX/SUBSTITUTION/ input.txt > input.txt" a bad idea? [duplicate]
This is a question from MIT 6.NULL lecture 4:
To do in-place substitution it is quite tempting to do something like sed s/REGEX/SUBSTITUTION/ input.txt > input.txt. However this is a bad idea, why?...
-1
votes
1
answer
43
views
How to add an empty line at the end of these commands?
I am in a situation where I have so many fastq files that I want to convert to fasta.
Since they belong to the same sample, I would like to merge the fasta files to get a single file.
I tried running ...
-2
votes
3
answers
40
views
Which tool would I need to return everything between two patterns if a third pattern exists anywhere in between the two? [closed]
I have a quite large file and I need to return blocks of texts with opening and closing tags only if the block contains a certain pattern.
For example:
[A]
Line 1
Line 2
match-pattern
line 3
line 4
[...
-4
votes
1
answer
50
views
Extracting just matching values from each line of a file? [closed]
I have numerous text files with several million lines that I need to extract matching patterns from, just to see where they occur in relation to each other. Here is and example of the input file:
UX|...
0
votes
0
answers
77
views
compare 2 columns of 2 different files with time difference [closed]
I want to get all the records from a file A.csv, if from file A.csv does not contain even a single record where a firm(column3) is same as in file B.csv(columns3) and time(column2) difference is ...
0
votes
1
answer
31
views
jq with regex in curl output
I have a below JSON
{
"router": {
"node_id": "ip-1-2-3-4",
"state": "HEALTHY",
"message": "OK"
},
...
2
votes
3
answers
61
views
change date in column 2 where numbers do not match column 3
I have tried this before but need to change direction. I was changing the numbers but I found I need to change the date after the numbers differ. My text has 3 columns and the 2nd and 3rd are similar ...
-1
votes
0
answers
6
views
Replace strings within two characters with sed [duplicate]
I want to replace this .json:
{
"house": "RED",
"oneString": "Data String=WORDA;Initial Catalog=WORDB;Internal SSO=True;",
"word": {
"...
0
votes
4
answers
74
views
How to use IFS= read when you have two input files to perform a sed to replace two values on specific line number?
I have a file names fileA.txt with "x" quantity of line numbers. I need to replace a string named No_IP_Found with an IPAddr but on specific lines. I have the line numbers I need to replace ...
1
vote
2
answers
33
views
sed replace regex match group
I've a file:
import "aaaa/bbbb.ccc";
import "dddd/eeee.ccc";
import "fffff/ggg/hhhh.ccc";
BLBLBL
BL2BL2BL
And I want to replace the path of the import like this:
import ...
0
votes
0
answers
31
views
Put grep/sed result in Jenkins file without "" to variable with checking that string not beginnig with comments '//'
I want to put a result from grep/sed to a variable.
// Checking PROJECT name validation. Must be without '.' & equal to globalProject name
stage('name validation'){
...
2
votes
3
answers
26
views
sed command replace muti line with reg
I got a text like this:
TOKEN = decrypt_aes(
"189272123124aqephkiz3")
And I want to change it into:
TOKEN = "189272123124aqephkiz3"
How can I make this?
I can do this when ...
0
votes
0
answers
28
views
i want to search for a value eg: /field in a file using shell script and replace the value that comes after /field omitting space after that
eg:file1 contains /field 377838 I want to search and replace the value after/field after space that is 377838 with another 397658 that I grepped from file2.
file1:
0 PIN_FLD_POID POID [0] 0.0.0....
0
votes
2
answers
48
views
Replace the matched string in the comma separated string pattern
I have a comma separated strings inside brackets and I need to replace the string in matches the pattern.
And we have unknown string at the start and at the end. In the below example I need to replace ...
-1
votes
1
answer
39
views
grep regular expression match for newline character is not working as expected [duplicate]
This is an odd issue that I run into when grepping for specific lines in file. For example, I have the following file I want to process.
$ cat file.txt
Lips
16oz
Total $XXX
The idea here is that I ...
-1
votes
1
answer
45
views
Remove lines that end with a string but keep the ones that contain it [closed]
Say I've got the following input
bash 1.14.8
bash-lic 1.14.8
aws 2.11.13
aws-lic 2.11.13
aws-licensing 1.11.20
aws-licensing-lic 1.11.20
I would like to remove lines ending with "-lic", but ...
-1
votes
0
answers
10
views
sed: explain command [duplicate]
I have file which contains data like this:
[1] Emperor
[2] King
and I want to transform it into this.
Emperor [1]
King [2]
We run it in a shell script.
A friend managed to solve it with this sed ...
0
votes
1
answer
27
views
How to use Linux watch against a command piping to sed
When I perform this command:
ip -s link show enp65s0f0 | sed -n '/ vf 4/,$p'
I get this output
vf 4 MAC 00:00:00:00:00:00, vlan 3932, spoof checking off, link-state auto, trust off, query_rss ...
1
vote
6
answers
62
views
Replace values in last column
I have multiple text in file.txt
4141 2019-01-08T14:42:55.000+02:00 JonhSmith LS08EE0I 30
2128 2019-11-02T13:47:34.000+02:00 James Davis RT84SO1 40
2293 2019-12-21T17:41:37.000+02:00 James Davis ...
0
votes
3
answers
52
views
Regex: how to match up to a character or the end of a line?
I am trying to separate out parts of a path as follows. My input path takes the following possible forms:
bucket
bucket/dir1
bucket/dir1/dir2
bucket/dir1/dir2/dir3
...
I want to separate the first ...
1
vote
4
answers
85
views
Conditionally remove first word of nth column using awk/sed
I have a tab delimited file, and in the 3rd column I want to remove the first word if the following are true: 1. the first word is all in lowercase, 2. the second word is capitalized. And following ...
0
votes
3
answers
35
views
Changing a line of text with sed with special characters
The name in the title says it all. However, I'm absolutely the worst with the sed command. So I'm trying to edit the following file:
/var/www/html/phpMyAdmin/config.inc.php
I want to edit the line ...
0
votes
1
answer
39
views
Insert ongoing number to multiple files - linux console
I'm having a bigger file (16192 times 0) that I need to split up into 500 character segments.
I do it like that:
split 1.txt -b500 1_split.txt
This gives me 33 files with 1_split.txtaa to 1_split....
1
vote
2
answers
68
views
Change all occurance of password in propertie file in Bash
I would like to change all password (to be encrypted) in a file, with a command and i'm stuck with my sed, i don't know how i can tell it to take the output of the sed
the example in my propeties file ...
1
vote
1
answer
49
views
How to modify configuration files using shell script
I have a .congifg file with the following content.
train_input_reader: {
tf_record_input_reader {
input_path: ["train.record-001",
"train.record-002",
...
-3
votes
1
answer
40
views
Convert double quotes to LaTeX double quotes [duplicate]
I'm converting a book from txt to latex and I'm trying to use the prober double-quotes behavior. Therefore I want to convert using sed this phrase:
"Wake up, Alice dear!" said her sister; &...
-2
votes
1
answer
37
views
How to cut particular part from file name in shell script [duplicate]
I am trying to cut the particular portion from file names but unable to do so. can some suggest please.
red-hat-parameters.json
docker-parameters.json
docker-kubernetes-parameters.json
docker-...
-1
votes
0
answers
37
views
String substitution using sed [closed]
I want to replace a string in a yaml file using sed. There is a string my yaml file as snapshot-id:1232. I want to replace this with snapshot-id:1235. What will be the syntax for this using sed ...
-4
votes
1
answer
41
views
How to swap strings on second row seperated by comma [closed]
I'm looking for the best solution how to swap the second row for the first two columns of a CSV file.
cat file.csv
Date,2022-04-18Z
2022-04-16Z,Date
Date,2022-04-19Z
Date,2022-04-20Z
Here you can see,...
0
votes
1
answer
35
views
concatenate within loop using sed
I have two types of files (A.n and B). A.n files are named A.1, A.2, A.3 etc.
In B file there is a word like 'Element.xyz' which I want to replace by 'Element_n.xyz' with all other things unchanged ...
2
votes
4
answers
57
views
Sed to add color to column for a specific pattern?
I figured out how to colorize column 3 in green like this:
green=$'\033[1;32m';off=$'\e[m';echo -e "num co1umn1 column2 column3\n=== === === ===\n1 this is me\n2 that is you"|column -t|sed &...
3
votes
7
answers
93
views
Multiline output to single line concatenation with delimiter string
I use this command to get a list of all the files that has changed in a pull-request.
git diff --name-only HEAD master
Sample output:
my/repo/file1.java
my/repo/file3.java
my/repo/file5.java
I would ...
-2
votes
1
answer
65
views
How do I unfold brackets using vim command with sed? - Sed Replace character with newline unless first character issue [closed]
I've got this config file that I'd like to unfold it's brackets from.
As far as I can tell I can best use the vim -e -c 'stuff goes here' command for this and put that inside a shell script.
Input ...
0
votes
2
answers
43
views
How to add # to two consecutive lines in one command
I would like to edit /etc/pacman.conf
In there, there are two lines which I would like to comment:
[multilib-testing]
Include = /etc/pacman.d/mirrorlist
I used sed to comment the first line like ...
0
votes
1
answer
46
views
Regex escape multiple quotation
I have bunch of crawled endpoint result from a domain, it was parsed in Json format. I've successfully aggregate the json to extract it's endpoint using sed and I wanted to merge all the sed command ...
-1
votes
1
answer
52
views
Trimming the end of words in a txt file [closed]
I have a text file in the form of a binary matrix. The headers of each column are in the format:
"ABCD-1S2S-123-01A" "ABCD-2D4F-245-01A" "ABCD-2K4K-013-01A" etc
Is there ...