Questions tagged [sed]
sed is a command-line stream editor for filtering and transforming text.
411
questions with no upvoted or accepted answers
6
votes
1
answer
1k
views
Why is sed changing permissions of a file on a cifs mounted share?
I have an Arch linux machine that uses the following fstab entry to mount a share:
//192.168.3.1/Documents /mnt/ cifs credentials=/home/tal/.smbcredentials,rw,x-systemd.automount,iocharset=...
4
votes
2
answers
348
views
Stuck With Using find and sed to Replace String in Filenames
Following this post as a reference, I'm able to run a find and sed command without it throwing an error, but the filenames remain unchanged.
Trying to strip pronunciation_de_ from all mp3s in the ...
3
votes
2
answers
119
views
why is this sed command failing to get the desired output
testfile:
872iirji -- RANDOM STUFF -- skjkfj45j
GET /_ajax_htmlview?action=28&__and_so_on HTTP/1.1.
Host: my.website.com.
connection: blah blah blah
skjfkjfj
desired output:
_ajax_htmlview?...
3
votes
2
answers
3k
views
Modify filenames in Makefile
For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with ...
2
votes
0
answers
104
views
Variations in variable expansion in bash between CentOS versions
EDIT: @steeldriver in the comments pointed to this being a bug in some versions of visudo in processing EDITOR=, [ Bug 942 - visudo fails if $EDITOR contains quotes ] - the correlation to centos ...
2
votes
0
answers
65
views
Might this script delete the file if fails?
I suspect that the following script, executed by root, under certain conditions, deletes /etc/hostapd.conf:
#!/bin/bash
CONFIG_FILE=/etc/hostapd.conf
read mac_addr < /sys/class/net/wlan0/...
2
votes
2
answers
167
views
using filename and path as strings to be replaced using sed command
I am trying to deal with the following situation. I have many files (more than 100) with an .html extension in a folder tree and inside those files I have a string which is the file name. For example ...
2
votes
2
answers
246
views
How to select first occurrence from between two patterns including them
What I have:
interface GigabitEthernet0/2/1/6.2061
description --> Some description here
service-policy input BESTEFFORT-IN
service-policy output Egress_30M
vrf VPN-s2s
ipv4 mtu 1500
ipv4 ...
2
votes
1
answer
56
views
Script to add a block in a few hundred files
I want to add the following lines
if ($http_user_agent ~* "somewebsite" ) {
return 444;
}
to all my vhosts in NGINX as follows
server {
location / {
want_to_add_those_3_lines_here
}
}
...
2
votes
2
answers
84
views
How can I prepend lines that don't start with certain keywords?
I'm modifying a bunch of python files and I need to prepend every variable declaration with 'self.'. Here's an example of what I'm trying to do.
From this:
class testClass(parentClass):
def ...
2
votes
1
answer
814
views
Why is sed failing to follow collate order?
On this command:
$ echo "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
> sed 's/[a-z]//g'
ABCDEFGHIJKLMNOPQRSTUVWXYZ
It seems correct, doesn't it?
However, the locale in effect is ...
2
votes
1
answer
241
views
Formatting and fill missed data based on column
I have the data in this format and I want to sort it based on the label in each column. Would want to replace the missing field by a comma (,) like shown below
2018-03-13 02:09:12,AB=123,BC=6,CAB=Jax,...
2
votes
1
answer
781
views
extract fasta entries from list using while read
I have 28 files that each have ~14,000 "entries". A single entry consists of a header, denoted by >string, a newline, and then a sequence which is a string. Each entry has variable length sequence/...
2
votes
0
answers
158
views
sed behaves strange on android tablet
Hi I'm new to using sed
When I type:
echo day | sed /s/day/night/
the output is:
nightday
In other words, it just appends the entire line after the substitution. I am using a Samsung Galaxy Tab ...
2
votes
0
answers
929
views
Getting a range of lines between timestamps from /var/log/messages
I want to get all lines between two timestamps from /var/log/messages.
I only have start time which I provide to my script as input.
The script then should get me all the lines till next day as output....
2
votes
0
answers
306
views
use gff2fasta instead of a bash script to get parts of DNA sequences out of a full genome
EDIT and a solution
Because my original question was badly phrased and I was trying to re-invent the wheel I am answering my own question now (maybe it helps someone else):
gff2fasta is a tool which ...
2
votes
2
answers
168
views
Replace characters in matched line
I have some text with ip inside it. I'd like to replace each digit in ip which is not followed by "SpecialWord" with some other character. There is can be more than one ip in each line.
For example:
...
2
votes
1
answer
206
views
Use sed to keep only parts of a file and reorder it (based on textWrangler grep syntax)
I want to edit a file called trial.fastq with the following format:
@NAME123.15.1 15 length=151
GTAGCNTACGGGAGGCAGCAGTGGGGAATTTTCC
+NAME123.15.1 15 length=151
AAABB#>>AABDGCEGGGFGGGHHHGGGFHHGHH
...
2
votes
2
answers
1k
views
How to copy strings from middle of lines (between strings) to the end of lines
I have a text file (1.txt) as follows:
word1
word2
word3
I use sed to add strings to the beginning and end of every line as follows:
sed 's/^/blahblah1 /g' 1.txt > 2.txt
sed 's/$/ blahblah2/g' ...
2
votes
2
answers
270
views
sed match word1 and word2 to get word in between
Im having issues with trying to pull an ip address our of a log file call full.
This is what the line in the file looks like
[2016-11-10 11:22:42] NOTICE[24518] chan_sip.c: Registration from
'"...
2
votes
2
answers
2k
views
Read from and append to file at the same time while preserving end-of-line
Conceptually I have an easy task... I have [loosely] structured data in a file:
Testing: debug, default CXXFLAGS
<100's of additional output lines>
Testing: release, default CXXFLAGS
<100's ...
2
votes
2
answers
226
views
Exchanging One Column From File1 with files from File2
I have two files. The first file has 11 columns, for example:
1 2 3 4 5 6 7 8 9 10 11
The second has 10 columns and might look like this:
11 22 33 44 55 66 77 88 99 100
What I want to do is look ...
2
votes
0
answers
353
views
sed stdin behaviour
Using sed for a direct stdin treatment of data, I expect that a line is treated after the enter.
This is what happens when I test on CygWin or Linux but on my AIX, a second new line is needed to treat ...
2
votes
0
answers
865
views
OpenWRT missing OD (octal dump)
I have a bash function using od command.
Now I'm trying to run in on OpenWRT and see that in has not od.
Also can't find it using install from opkg, because I can't find it.
Is there a possibility to ...
2
votes
2
answers
555
views
Compare sets of values from two files and print the output in a third file using awk
I have a problem comparing two files. I'll try my best to explain. I have two files f1 and f2 which I have to compare on basis of two sets Parameter(p) and Value(v).
Basically f1 contains a list of ...
2
votes
2
answers
1k
views
Insert a line after a block of text with sed
I have text file: file.conf
### Option: LogFile
# Name of log file.
# If not set, syslog is used.
#
# Mandatory: no
# Default:
# LogFile=
### Option: LogFileSize
# Maximum size of ...
1
vote
0
answers
28
views
Rework sed for vim's errorformat for circom compiler
compiling ciruits and intend to use quickfix. but the compiler output was not in standard format ... so tried parsing
Need help
fixing the sed command
preping the output for error format so that i ...
1
vote
0
answers
38
views
SQL output piped to `kubectl exec` crashes, if not replacing TABS with SPACES
The context:
I'm generating SQL from a backup dump, inside a subshell, to then pipe it to mysql for execution:
(
echo "SET FOREIGN_KEY_CHECKS=0;";
tar --to-stdout -xvjf archive.tar;
echo &...
1
vote
2
answers
151
views
How to programmatically maintain umask in /etc/profile and /etc/bashrc
I am looking for a way to programmatically maintain a consistent umask in the files /etc/profile and /etc/bashrc. They have an entry such as follows:
if [ $UID -gt 199 ] && [ "`/usr/bin/...
1
vote
0
answers
32
views
sed + how to be sure that sed replaced the value correctly
here is a nice example how to replace the value on match key on file
str="192.2.34.40:2181,192.2.34.34:2181,192.2.34.32:2181,192.2.34.52:2181,192.2.34.53:2181"
sed -i "s~^[[:space:]]*...
1
vote
1
answer
36
views
How to remove every pattern match and write it in new file
So i have a long string that have no blanks and i want to remove every time the pattern match.
This is how the string looks like:
bdy11<entryunit="phoenix"><name>costperdps</...
1
vote
1
answer
48
views
Unix Script - On specific pattern, need to exit tail -f, and use awk to run separate script
So, I need to make a modification to a start script to clean up the /tmp once the application is fully loaded. After some research, I found a command for my script that does this:
tail -f /home/user1/...
1
vote
1
answer
109
views
Rename hundreds of filenames to replace or delete specific words including duplicated words via MacOS Terminal (bash/sh/zsh?)
Summary
I have thousands of pictures that were titled in full sentences. I am trying to automate a way to do clean them up with a single script, and then reuse that script as I add more pictures.
The ...
1
vote
1
answer
117
views
How do replace a specific part of a line using sed without replacing the rest of the line?
Suppose I have the following file called Product.java:
public class Product {
public String name;
public String description;
public String picture;
public double price;
public ...
1
vote
1
answer
61
views
Editing a file without it being executable
I have a file secretinfo.txt inside a directory SensitiveData that I am trying to edit.
Currently, the directory and file have the following permissions:
drwx------ 2 www-data root 4096 Apr 20 17:39 ...
1
vote
1
answer
92
views
Translate VS Code Editor regular expression in to sed regular expression
How to translate from moderen editor regex to sed syntax?
Seasoned developer, but complete sed noob here, thank you for looking.
Working on Pop OS Linux 20.04 LTS
I "cook up" my regular ...
1
vote
3
answers
56
views
Find matching text in consecutive lines and increment numeric value in the following line
I'm trying to find a string(Name2) in a file and match the version(*abc-xyz-0-197) in the next line and update the ID line with an incremented value.
How can this be done?
The file looks like this:
...
1
vote
1
answer
326
views
Replace string with line range from another file, including modification of line range on replace
I have two files of code, the first (File1) including a few lines of text to be included and the second (File2) including strings that will be replaced with a range of lines from the first file. The ...
1
vote
0
answers
38
views
Capitalise few characters in a word
This might be a crazy scenario but just wanted to know is there any way we can capitalise few of the character in a word without a delimiter (to identify the character to capitalise )
For eg:-
I/P
...
1
vote
0
answers
870
views
Search and 'in-place' replace strings in binary file
I want search and 'in-place' replace strings in binary file (case-sensitive, colon-separated strings). What method would be more clean, sed or bbe?
sed -i.bak 's/F:O:0/B:A:R/g' file.bin
bbe -e 's/F:O:...
1
vote
1
answer
306
views
sed delete lines not matching patterns in txt file
I'm dealing with a txt file that lists a bunch of other txt files, a lot of which I have wrongfully duplicated.
I'm on macOS so the lines listing the duplicated files all end with the pattern (NUMBER)....
1
vote
0
answers
71
views
Inconsistent behaviour when piping output of Tail into Xargs through an editing command
I'm giving in to asking the SE spirits for assistance. I will expand in detail below, but I've boiled the inconsistency down to these 3 lines. I am trying to grep a string in between single quotes (...
1
vote
2
answers
204
views
Extract method name and add it for logger as first line of method
I have a requirement in which Java method name needs to be added in logger in the first line of the method.
I am trying the following approach.
Get lines with keyword private, protected or public ...
1
vote
0
answers
215
views
how to embed command substitution in sed?
from this answer:
Using a command inside a sed substitution there is used this to make command substitution:
echo aaabbdd | sed -e 's/a*/echo `echo -n & | wc -m`/;e'
When I shell use double ...
1
vote
2
answers
53
views
I want to only remove grouped commas from this csv to change the number of variables to two
I have a csv where the first few rows look like this
c("4288", "57534"),MIB1
c("2272", "2385"),FHIT
c("5550", "10531", "56239"),PREP
c("25809", "23669"),TTLL1
I want to manipulate the number of ...
1
vote
1
answer
276
views
AllowGroups in the /etc/ssh/sshd_config file
The following sed command adds my_unix_admins to the end of the lines starting with the word AllowGroups.
/bin/sed -i '/^AllowGroups / s/$/ my_unix_admins/' /etc/ssh/sshd_config
I want to only add ...
1
vote
2
answers
490
views
sed command is not working to remove the special character ( Copyright and trademark symbols )
I am trying to use sed command to delete the copyright characters.But it is not working. Below is the command which am using.
sed 's/; © E/; (c)/g' input.txt > output.txt
but when am using vi ...
1
vote
0
answers
2k
views
How to use sed to replace variable value with a variable of the same name?
I'm trying to write a script that updates a server config file to the latest format. The purpose of the script is to copy over existing (defined) variables to the latest config (in a temp file), then ...
1
vote
1
answer
33
views
BASH: Renaming and organizing files based on information in the filenames
Suppose I have a bunch of files has information separated by underscores:
nickname_username_realname_date_filename.txt
I want to make a directory for each username and rename the file to get rid of ...
1
vote
1
answer
469
views
sed: -e expression #1, char 24: unterminated `s' command
Using sed I need to replace variables in an HTML document.
The following is what i am using:
cat $email_temp\
| sed 's/\$message_entry/Flex File Export completed successfully for'"$run_date"'./g'\...