Questions tagged [sed]

"sed" ("stream editor") is a Unix utility that parses and transforms text files.

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

keep each line containing x only if column y is the first containing x. remove the rest containing x

I'm trying to reduce a results file that contains multiple results for sometimes the same query and I only want the top result from each query. Using bash and bash tools like awk, sed, etc. I would ...
user avatar
0 votes
1 answer
18 views

sed remove with regex

I have code that contains #ifdef CEEDLING_TESTS void scheduler_task_delay_update(uint8_t task_index) { #else static void scheduler_task_delay_update(uint8_t task_index) { #endif I want to remove ...
user avatar
1 vote
1 answer
20 views

Sed match and replace only certain characters

I have mutliple strings in very similar format. (#1111111) (#4444444) I was trying to use sed to provide an output: 1111111 4444444 I have tried: sed 's/(#[0-9]+)/^[0-9]+/g' which seems to match ...
user avatar
  • 13
0 votes
1 answer
31 views

Removing Duplicate from File

I have two files fileA and fileb FILEA 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 5.5.5.5 FILEB 4.4.4.4 2.2.2.2 Output should be 1.1.1.1 3.3.3.3 5.5.5.5 Size of File A is around 60GB and Size of File B is 1GB ...
user avatar
  • 15
0 votes
3 answers
47 views

sed will not execute as a ssh remote command

I'm working on a script that lets me delete old public keys from a server via ssh. The issue seems to come from the formatting of my ssh command here: ssh -qo ConnectTimeout=20 "${user_ssh}@${ip}&...
user avatar
0 votes
1 answer
23 views

Replace string from and including '_' up to excluding ':' script? [duplicate]

I am trying to remove a string from and including one char, '_' up to but not including another char, ':'. Everything is on the same line. I have files with different names and numbers, that contain ...
user avatar
0 votes
1 answer
24 views

How do I use sed to parse a string that includes hyphens?

Input example: foobar_1-1 1024 x 1024 Desired output foobar_1-1 The hyphen is causing issues here. It's causing the output to be two items in the array: foobar_1, 1 Any advice?
user avatar
-1 votes
1 answer
68 views

Remove everything between 2 chars using sed

I am trying to remove a string from and including one char, '_' up to but not including another char, ':'. Everything is on the same line. I have files with different names and numbers, that contain ...
user avatar
0 votes
1 answer
47 views

Append a line to the end of the file using ssh, sudo and sed

I have an obvious problem with quoting in bash such that I couldn't really solve for a while. Here is a loop with executing a remote command in a sudo-subshell on a remote server via ssh: for HOST in $...
user avatar
  • 172
0 votes
1 answer
41 views

Piping PCRE grep into sed

I wanna sed this file, but the BRE in sed is not working as well as I hope. What I have now is basically just : $ cat Dungeon | grep -P -o '<\/.*?>' My question is how do I sed this? I want to ...
user avatar
0 votes
4 answers
62 views

Shorten a text that is too long (with sed?)

I have the following example of a .csv-file "0a","1a","Short text","abc" "0b","1bx","Here is a very long text","def" &...
user avatar
1 vote
1 answer
24 views

How do I replace both matching patterns in a line using sed?

TL;DR Given this: $ echo "-lngtcp2_crypto_openssl -lnghttp2.14 -lnghttp2 -lnghttp3.0" | \ sed "s: -lnghttp2[^[:space:]]* : lib/libnghttp2.a :g" -lngtcp2_crypto_openssl lib/...
user avatar
  • 359
-1 votes
2 answers
78 views

I have a list of searching word. How to replace them in another file?

I'm sure this question is asked multiple times, but I fail to find it. Basically I have a text file, and a list of all search strings (e.g. cat, dog, banana, etc). I want all occurrences of those ...
user avatar
  • 1,761
0 votes
1 answer
28 views

Regex with first line

I want to search inside the but replacement the firsh character of line. for example, line is this pool 0.ubuntu.pool.ntp.org iburst maxsources 1 I want to search pool.ntp.org add firsh character # ...
user avatar
0 votes
2 answers
34 views

GNU Sed breaks with tab a a delimiter?

I am wondering what is going wrong here. Using a space as a delimiter works but with a tab it seems to fail. % sed --version sed (GNU sed) 4.8 Copyright (C) 2020 Free Software Foundation, Inc. License ...
user avatar
  • 1,206
0 votes
2 answers
65 views

Remove the file name from a messy path in a text file awk or sed

I have an xml file with many lines containing something like this: Save="C:\Users\Administrator\Desktop\my files\1020\A54f\Drawing965.DWG" Module="0" Save="C:\Users\...
user avatar
  • 35
0 votes
1 answer
264 views

BASH converting txt to csv

BASH/scripting newbie here. sed 's/ \+/,/g' output3.txt > output.csv This one gave me so many delimited. I only one to delimit the "pipe" | symbol and leave the rest as it is. So ...
user avatar
1 vote
1 answer
103 views

How to best use SED to comment out a config value while adding a new config value right after it?

I want to edit some config files on in the CLI without a wysiwyg editor but instead using sed. Is there a best practice for doing that? Here are a few examples of what I mean: Config file example 1 A ...
user avatar
  • 11
1 vote
2 answers
508 views

Find and replace text in a file after match of pattern only for first occurrence using sed

Let's say I have the following input file: Server 'Test AB' option type 'ss' option port '1234' option timeout '60' Server 'Test CD' option type 'ss' option port '1234' option ...
user avatar
1 vote
0 answers
22 views

use bash script to remove tracking from google scholar links into non tracking links for wget

I Get regular google scholar emails. I am trying to make a simple script that lets me download the pdfs / articles, without google tracking me via their urls. Up till this point I have been copy ...
user avatar
0 votes
1 answer
35 views

How to replace a line in sed with unknown amount of whitespace?

I would like to replace a line in a config file with sed. But the line I am trying to replace contains an unknown amount of whitespace: conf is foo conf is bar config is foobar I've ...
user avatar
  • 411
0 votes
0 answers
20 views

Avoiding the Pre-boot-authentication password prompt for non root/boot drives

I have an Ubuntu system which boots from a small NVME disk using software encryption, TPM, etc. to mitigate against data loss in case of theft. The system is interfaced with customised PCIe hardware ...
user avatar
  • 101
8 votes
2 answers
2k views

Emptying HTML tags with sed

I want to empty the content of every HTML tag but "keeping the structure". From: <h5>Holdrs <div class="tooltip" data-tooltip="Accounts with ..."></div>&...
user avatar
  • 91
0 votes
1 answer
23 views

Match pattern and any character after up to space, and rearrange captured patterns with sed

I would like to find a particular pattern (k__), and any characters after it, up to a space, and then move that captured pattern to the end of the line With this example file: cat test.file 37099 ...
user avatar
0 votes
1 answer
57 views

Pipe Output of dhclient with sed

Goal Limit output of dhclient. Code dhclient eth0|sed 's/answers//' expected behaviour RTNETLINK : Operation not permitted got RTNETLINK answers: Operation not permitted Piping ifconfig works ifconfig ...
user avatar
  • 138
0 votes
1 answer
184 views

sed RegEx matching for full/partial string

I'm having some trouble creating a RegEx string for sed. I tested the expression with various online services, and there, it does succeed. But not so with sed, unfortunately. This is my testing sed ...
user avatar
  • 2,142
1 vote
1 answer
152 views

Using the output of a piped sed for the replacement value of a second sed

I am trying to get the version of a npm package, and use it to replace the value in another file. Specifically, I want to get the package.json version and use that to replace the wordpress style.css ...
user avatar
2 votes
1 answer
223 views

Batch removing specific text in .txt files

I have 30+ text files that I want to remove specific lines of text from. They all have different names (which I need to keep), they are in the same folder. The text will not all be on the same line ...
user avatar
0 votes
2 answers
44 views

How can erase first character of all string in file

How can erase first character of all string in file if this is zero? e.g I have file $ cat file 01111111 01222222 6666066 09999011 02222044 0743333 01000000 30000000 2222220 Try with sed command ...
user avatar
0 votes
1 answer
55 views

BASH - How to combine data from 2 files

I have 2 files with the following data file1: datapoint1name##datapoint1name datapoint1name.PercentUtilization= datapoint2name##datapoint2name datapoint2name.PercentUtilization= datapoint3name##...
user avatar
  • 181
0 votes
2 answers
184 views

Delete pattern matching regex from sed capture group

I'm trying to remove all instances of '_(one number)' from certain strings in a file. So tig00000003_1 should become tig00000003 This is what my test file looks like: ##sequence-region tig00000001_732 ...
user avatar
  • 1
0 votes
1 answer
357 views

how to get value after colon with sed

I have these: variable="call_type: I alert_id: 2334 server: serverA run_as: sub_ap: FRUIT...." I need only one command to get value of the variables. I try with these: callType=$(echo $...
user avatar
0 votes
2 answers
517 views

sed cannot interpret a literal hyphen

I'm using sed on a command line to edit a file. This works: sed "1,/abc/d" file1.txt > file2.txt It excises everything in file1.txt up to and including the abc. But this doesn't: sed &...
user avatar
0 votes
1 answer
27 views

how can I replace a string from a specific character with string?

Using "sed", I would like to replace every "=" and what comes after it to a space. For example I have this line: VNN=VNN VNNSRAM=VNNSRAM VSS=VSS and I like to change it to: VNN ...
user avatar
0 votes
1 answer
207 views

Replacing a string when it is not followed by string with Sed

I am looking for a sed script to replace a string when it is not followed by a string in the content of a file. Currently I am at this approach sed -i -E "s/${filehash}(?!.de)/${filehash}.de/g&...
user avatar
0 votes
1 answer
140 views

how to replace commented line with sed

I want to replace below line with sed so I am trying below command which is giving me error "sed: -e expression #1, char 59: unknown option to `s'" I have not known to sed much can you guys ...
user avatar
0 votes
2 answers
48 views

Grep Sed with bash

I'm trying to achieve the following using bash and sed where the file containing below strings qa2.test.m.xyz.com 554 1723 21 qa88.test.nj.xyz.com 1723 554 21 443 80 qa2.lite.xyz.com 554 1723 21 ...
user avatar
  • 45
0 votes
1 answer
297 views

Remove double quotes embracing variable strings from terminal

I have several files that contain this kind of line: from="$variable_name" and other stuff $variable name can change, so I could have from="$myArray" and other stuff from="$...
user avatar
  • 113
0 votes
0 answers
84 views

how to use sed with variable when special characters in variable?

I want to use sed with variables. But my variable is changeable and unknown by us and maybe my string has got some special characters. My concern is if these special characters are the quotes like ' ...
user avatar
  • 192
0 votes
1 answer
25 views

How to append a carriage return to replacement text in osx bash script

I've tried numerous answers that I searched for here, and for some reason nothing is working I have a bash script which I'd like to use to process a series of files. Here's a simplified example a sql ...
user avatar
0 votes
1 answer
48 views

Change the file content with bash

I have a question regarding manipulating a file content using bash. So I have a conf file has the content as below: #set_var EASYRSA_REQ_COUNTRY "US" ...
user avatar
  • 3
1 vote
1 answer
29 views

sed/awk: convertion of multi-column data

I am operating with multi-column data file procuded by some AWK script: # output.csv lig12, dG(rescored) 1, 0.596625 2, 1.05873 3, 1.11285 4, 0.697402 I need to modify this output.csv to one line ...
user avatar
  • 147
1 vote
1 answer
148 views

Use sed/awk to add specific text from one file to beginning of another file

I'm trying to use sed/awk to copy a range of text from the beginning of file1 to a specific line. Then add that output to the beginning of file 2 for a script I'm writing. The following command does ...
user avatar
  • 11
0 votes
2 answers
22 views

Extracting data from text file by specific characters

I have a program that reads from a sensor and prints on stdout. The interesting data for me is just the X,Y and Z values: [2021-05-07 10:47:41.993] [info] Acceleromter (avrg 100): X=+6696.080 Y=-5577....
user avatar
  • 105
0 votes
2 answers
298 views

awk Removing Double Quotes from CSV File Quoted Strings separated by comma

I have a csv file I would like to remove any rouge " or , in it. The problem is all my fields look something like this "***********","*********", where * = can be any ...
user avatar
  • 1
0 votes
2 answers
307 views

(vim) How to remove word that has a specified character?

so I tried to remove any word that has a letter "a" in it with vim I want to change this string hotel echo lima lima oscar whiskey oscar romeo lima delta to hotel echo whiskey romeo I hope I ...
user avatar
4 votes
1 answer
262 views

Subshell won't work as indented

I have some files like this: ├── abc.conf ├── def.conf ├── xyz.conf ├── 10-abc.conf.postix ├── 10-def.conf.postix and I want to remove the .postfix from all files which starts with 10-. To do this ...
user avatar
  • 143
0 votes
1 answer
29 views

Using wildcards to do mass copying to slightly different names

I want to copy many files inside a single directory. An example filename starts with error042021.mysite and I want the new name end with -dev.co.at.txt. I think I need a wildcard for the number, ...
user avatar
0 votes
2 answers
36 views

Auto-filling/bypassing SED password screen

I would like to use a Self-Encrypting Drive in an embedded Linux application, but since it is embedded (i.e. no monitor, keyboard, or mouse), I have no way to enter the password on boot. Is there a ...
user avatar
  • 103
1 vote
1 answer
29 views

regex help: Replacing characters

I want to change characters in a json file. I tried some commands but didn't find a solution. Input: { "cpu" : 0.0789131391278358, "disk" : 0, "diskread"...
user avatar
  • 13

1
2 3 4 5
20