Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sed]

Sed stands for Stream EDitor - one of the basic tools in the POSIX environment. It processes one or more files according to an editing script and writes the results to standard output. Created in Bell Labs, it has been around since mid-70s.

0
votes
2answers
35 views

Delete a log while is written using SED - /var/log/messages

I had a filesystem that was over 60%. I found that the file /var/log/messages had more than 4 million lines so I decided to delete 2 million lines in order to clear some space. I executed the command ...
2
votes
1answer
22 views

How to stop sed from breaking when in combination with apg?

I am writing a script that will install WordPress automatically for me, to make my life easier as I have to deploy WordPress installs constantly. However, I am trying to make it so I never have to ...
0
votes
0answers
58 views

Merge two JSON strings with jq

I've been banging my head against the wall with this one a little bit, partially because I'm new to jq. I have JSON output from one command (terraform output -json). I want to take this data, rename ...
0
votes
1answer
26 views

Update all Python files via Linux command

In my original Python files I have the following: from official.utils.flags import _base I need to change it to: from utils.flags import _base My file structure looks like this: . ├── README.md ├─...
0
votes
2answers
33 views

SED to search for and delete ip with a partial match

I have various bash scripts that run, they scan log files for folks who try and make mischief, spam us and so on. I have been struggling with this for some days trying to figure this out. I have a ...
0
votes
0answers
14 views

Why sed gives different result in script and in terminal?

CALL_TOKEN=`echo "$1" | sed -e 's/[^a-Z0-9]*//g'` fn_debug "First element: $1" fn_debug "CALL_TOKEN: $CALL_TOKEN" Why CALL_TOKEN is an empty string? If I run same commands on the same server ...
0
votes
2answers
37 views

Adding a new line from file using sed

i'm trying to add a new line with data from a file to another file. The problem is, the data in the source file is with whitespaces so i do not get everything included. Here's my code: Source File: ...
1
vote
3answers
77 views

How to compress spaces in bash command output?

I work on a small screen and I'm trying to make the output of this command shorter, but I cannot get it to work. Command: docker container ls --all Output (too wide!): CONTAINER ID IMAGE ...
0
votes
1answer
32 views

Using sed to remove "(double-quotes) on code lines while leaving them on real comments in a vimrc [closed]

I'm finally learning how to use sed to edit configs while installing Ubuntu(Server/Desktop). After much gnashing of teeth and searching about for the proper syntax to not remove the "(comment double-...
1
vote
2answers
66 views

sed removing line breaks tail

In my Python script I needed a fast/efficient way to set a max filesize on a file I'm constantly writing to. Rather than bring the whole thing into py's RAM, I ran this shell command: sed -i '1d' ...
0
votes
1answer
26 views

delete some char set from the last column linux

I want to the delete everything after hyphen "e-" in the last column output.. Below is what my output looks like.. # awk '/out: OpenSSL/ { gsub( /[][]|out:/ , "" ) ; print $1,$2,$3 }' sslcheck.log |...
0
votes
0answers
119 views

sed + delete duplicate lines except the first one according to specific request

in /etc/services file I can see duplicate lines for example the following line is duplicate ( or more ) odasrv 2432/udp so it can easily deleted by sed as the follwing sed -i '/codasrv ...
1
vote
1answer
59 views

using sed to remove character at the end of numeric string

Here's a sample of my source file: USC00020958 -7777S 656S 721S 803S 891S 975S 972S 941S 906S 809S 695S 605S USC00021001 378S 389R 448R 522R 628R 736S ...
1
vote
3answers
43 views

Sed or other script, and regexp solution for cutting a filename

What I need is to get 2-3 variable from filenames. I use: FILES=$(ls -tr .../Files/) for f in $FILES; do ...... The files look like this: [letters and/or numbers and (underscore or nothing)][6 ...
-2
votes
1answer
25 views

sed search and add some sting

======KVM 虚拟化手册====== =====简介===== =====安装和配置kvm虚拟化===== ====检查是否支持KVM==== ====安装kvm虚拟化平台==== ====配置nested virtualization==== ==== 配置网络==== ====重启系统并检查相关配置==== =====virsh创建 & 安装虚拟机===== ====...
2
votes
4answers
155 views

Find and replace string between two delimiters

How do I replace a string between two delimiters? Some of the answers I found are close, but I think my need is a little more complex. I.e. smb.conf contains a blank line between shares. I want to ...
1
vote
2answers
36 views

HKPK Public Key Pinning - Auto add bash script

I recently started using HKPK Public Key Pinning. I have an automated script that generates my csr, certificate, and installs into apache2 on opensuse leap 42.3 I'm looking for a way to add spki ...
0
votes
1answer
55 views

sed for replacing non-commented lines in file

I have searched and have found well-informed answers that I think should work, but I can't get them to work. The problem is that I clearly so don't understand sed and all of the slashes and what any ...
0
votes
2answers
342 views

SED on Bash Script : how to replace text with special character that come from variable on Bash script

first, there is a variable that contain special character on bash script. here is the example. list.txt : user = root password = 1234 Bash Script : #!/bin/sh var1 = var&2018+& find . -name "...
0
votes
1answer
45 views

Remove all “Allow From All” from servers .htaccess

I have shell access to a web server that is being used for staging sites. Needless to say, there are a ton of "staging" websites on it. The paths are like: /home/ACCOUNT/public_html and we have set ...
0
votes
2answers
138 views

Sed command to replace code in every files

sed -ri '1 s/.*<\?php \$xgzdxgn.*\$tdjwdrzy.*\$vbtpmtzqq-1; \?>//g' *.php How to run this command on folders and sub-folders in a single command ( for all php files ). when i try to use this ...
1
vote
1answer
701 views

Openssl s_client: extract last certificate

I can ouput all the certification chain from a remote website by using the following command: openssl s_client -connect www.google.fr:443 -servername www.google.fr -showcerts 2>/dev/null | sed --...
1
vote
1answer
113 views

Cannot replace string with sed. Getting unknown option

I am trying to replace a string with sed (stream editor), however I am getting errors thrown back. Probably because I am not using the string correctly, because of the symbols. I am trying to replace ...
1
vote
2answers
56 views

How to extract the last two (or any number) directories from a path with sed?

I'm really looking for a generic solution here, but for the sake of example, let's say I'm looking for the deepest 2 directories in a path. e.g.: Given a path /home/someone/foo/bar, how can I use sed (...
0
votes
2answers
170 views

replacing space with new line characters for vagrant box use

I am trying to setup vagrant box using shell script where in I am storing key and cert files. Normal format of any cert or key file is as below -----BEGIN CERTIFICATE----- ...
-1
votes
1answer
79 views

validate file content with bash Regular Expressions + Linux

how to validate the following file content that should be include single integer/float number by bash Regular Expression or any other idea with awk/sed cat /var/VERSION/Version_F35_project_usa 2....
0
votes
2answers
212 views

How to insert a complex line between two single quotes in sed?

I have this line in the file /var/lib/pgsql/data/postgresql.conf: # archive_command = '' # command to use to archive a logfile segment we need to uncomment the archive_command parameter, ...
2
votes
0answers
305 views

Encrypt disks using SED and store keys in TPM?

I'm buying servers lately and all of them have disks that support TCG Opal full-disk encryption (aka SED). What I'd like to do is: Store data encrypted-at-rest on the disks (NVMe & SAS). Not be ...
0
votes
1answer
310 views

SED not working with complicated string

I have a file that starts like this: [global] pid = /var/run/php-fpm/php-fpm.pid error_log = /var/log/php5-fpm.log and want to replace error_log = /var/log/php5-fpm.log with error_log = /var/...
1
vote
1answer
140 views

multiline into single line and output to logger

I have a log file where data entries are as follows Each entry starts with time: time: 20170509123420 dn: uid=abc,ou=People,dc=test,dc=example,dc=com changetype: modify replace: ...
0
votes
1answer
478 views

Trying to do grep and sed from a file and push the output into a variable

Can we do grep and sed from a file and push the output into a variable grep "^/dev/disk/by-id/scsi-*" /tmp/disks.txt | sed '{'s/=.*//'}' Output would be like this: /dev/disk/by-id/scsi-...
1
vote
2answers
78 views

How to retrieve first N and last M lines from input in fish?

I have an input like: 1 2 3 4 5 6 7 8 And I'd like to retrieve only N first and M last lines from this input. For example, if N is 2 and M is 4 I want the result to be: 1 2 5 6 7 8 Lines can ...
-3
votes
1answer
32 views

How to change a users shell in passed with script

I am writing a bash script to change a users shell in passwd and have it be called from Rundeck. I have tried awk but I like the inline editing of sed. But I am not sure what shell the user had to ...
-1
votes
1answer
78 views

how do i remove local ip from list of ip addresses?

I have a variable that contains list of ips and i will like to remove the ip of the instance where the variable is set Please see below [root@ip-10-10-2-100 ~]# INSTANCE_IP=$(curl -s http://169.254....
-3
votes
1answer
143 views

Sed replace path for directory from special file with delimirers slash

i should change on parameter to other from template file in linux. sed -e "s/\${dir}/<in this place i should input path, like /home/username>/" /etc/nginx/site.conf But it does not work. How ...
1
vote
3answers
2k views

removing first and last character on each line / sed

I need sed to remove first and last character of the line for instance source (192.168.3.0) result 192.168.3.0 trying this way: sed 's/^.\(.*\).$/\1/' but then it removes 0 character as well ...
1
vote
2answers
165 views

BASH - sed replace IP variants

It's been awhile since I've posted a question on here. Need some assisteancew getting my sed to work. I've tried all kinds of forms of sed options, but can't seem to get this working. I have a file ...
0
votes
2answers
4k views

Unable to replace path using sed

How can i replace a path with another path in file using sed command, And when it is used as a variable in script it is working. sed -i "s/"system_filter = /etc/define_filter_file"/"system_filter = /...
0
votes
1answer
60 views

Parsing the time data from last command which has total “00:00” time spent on the last column

I have last command output for the hundred of Servers collected into the File,the problem is now is output is "Feb,Jan,Feb" meaning that its taking the Feb output of last years as well, So, i'm ...
0
votes
1answer
1k views

Sed replace string within quotes

I am trying to replace string within quotes in a file! Here is an example : <?xml version="1.0" encoding="UTF-8"?> <Context> <Manager pathname="" /> <Resource auth="Container" ...
-4
votes
2answers
110 views

Error executing help manual pages on Fedora 25 for all kind of man pages

[user1@testMachine ~]$ lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:...
1
vote
1answer
99 views

How do I replace the last period found before the first comma sed

Pretty new to bash/Linux and I'm trying to do the following I have a csv with hostnames and other information like so host1.servers.com,serverA,location host2.servers2.farm.com,serverb,location a....
0
votes
2answers
72 views

Replace a string once another string has been found

I'm programmatically building boxes, but I need to update a .repo file for PHP which has the following contents: # Repository: http://rpms.remirepo.net/ # Blog: http://blog.remirepo.net/ # ...
0
votes
1answer
57 views

Need script to replace TEXT in selected files

Environment Windows 10, C:\Folder_With_VMXfiles, installed sed for windows Tools: Batch script, sed for Windows Requirements: In folder C:\Folder_With_VMXfiles Need to replace some text inside the ...
-1
votes
1answer
570 views

Matching end of file with ansible lineinfile

I'm trying to replicate the following sed snippet in ansible's lineinfile module. sed -i '/# The named pipe \/dev\/xconsole/,$d' /etc/rsyslog.conf I know that I can template the file or brute force ...
0
votes
1answer
79 views

Why does replacing a string in files with find and exec sed not work

Goal is to replace all references to my old email. I tried find /var/www/vhosts/ -name '*.php' -type f -exec sed -i 's/old\@email.com/new\@email.com/g' {} \; Yet it just shows nothing. It goes on ...
1
vote
1answer
1k views

How to replace an entire NGINX block with sed?

I am starting to learn bash script and need to write a script to install fastcgi_cache on NGINX. I need to replace the default location for PHP with the one with the fastcgi_cache settings. To be ...
-1
votes
1answer
1k views

sed insert line on first blank line after XXX

I am interactively editing my hosts file with a bash script. I need to insert a line in my hosts file. The line needs to be inserted on the first blank line after a specific comment. The content I am ...
0
votes
2answers
4k views

How to use sed to replace text with special characters

I currently have a script that generates random words to create passwords. I run this by selecting the script and letting it know how many words I want .e.g ./generate_passwords.sh 5. This creates ...
-5
votes
3answers
337 views

Search for a word before white-space

I've got a file with some e-mails: info@example.com info51351@hotmail.com test@hello.com test6261@gmail.com example@example.com example64262@gmail.com And now... I need to find a way to search for ...