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.

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

Using sed command to replace config file with comment in linux terminal

I know a little about sed. In /etc/nanorc I got bunch of settings with comments (eg:). #bind ^K setting 1 #bind ^F whereis all #bind ^J setting 3 So, I want to comment out only this setting to ...
2 votes
2 answers
220 views

Extract missing paths from bash array of paths [closed]

I have an array of paths: paths=( /foo/exists1 /foo/exists2 /foo/missing1 ) To find those that are missing: ls "${paths[@]}" 1>/dev/null Shows: ls: cannot access '/foo/missing1': No ...
1 vote
1 answer
167 views

SED returning error 2 when launched by Wpkg

Case I am deploying a software product using Wpkg over Windows workstations. I need to disable product's faulty automatic update and the best solution in this case is to modify one configuration file ...
1 vote
2 answers
14k 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 = /...
12 votes
4 answers
18k views

SED replace across multiple lines

I am trying to find these three lines: <!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> --> and replace them with: <Connector port="8009" protocol="AJP/1.3" ...
1 vote
1 answer
757 views

mask public IP addresses from any command output (for diagnostic)

I'm writing a script to extract information from BusyBox v1.25.1/Linux 2.6.36/router where the user can simply run the script and copy/paste the output into a submission form to request support. The ...
0 votes
1 answer
78 views

Use sed to strip out multiple cases with varying names

I have an ansible inventory that I need to remove all cases that start with site2-. For example I have a list that includes groups named: [site2-static-web] site2-ansible site2-accounts site2-admin ...
5 votes
2 answers
24k views

use SED recursively in linux?

I want to implement the following command recursively sed -i 's/href=\"1\//href=\"\/1\//g' ./* so that it replaces all href="1 with href="/1 in all sub-directories. Is there a flag I can add to ...
0 votes
2 answers
2k views

How do I cut just the file name from from ls -l output? [closed]

I am in the process of concatenating ogg audio files in bulk with the help of ffmpeg using a mylist.txt file The format of the mylist.txt file is file '/path/to/file1.wav' file '/path/to/file2.wav' ...
1 vote
3 answers
14k 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 ...
2 votes
1 answer
16k views

How to use Ansible modules replace or inline instead shell command with SED

i have file with string: MYAPP.db.username.DEV=MYUSERNAME Where: MYAPP mean name of applications DEV means environment MYUSERNAME means name of user for connection to db I need to replace these ...
0 votes
1 answer
246 views

Convert date format in file

I have a file with the current date format 11.22.33.44 - - [2019/08/02-01:23:50+0000] GET www. 1111:2222:3333:4444:5555:6666:7777:8888 - - [2019/08/02-01:28:18+0000] GET www. And i need to convert ...
0 votes
1 answer
179 views

Convert date and time from output

I have a file with date and time on a couple thousand lines. I need to convert: 2019/08/02-01:23:50+0000 To: 02/Aug/2019-01:23:50 +0000 I so far have th=`grep ...
0 votes
2 answers
595 views

Parse Date from Text String in a 3 column format

I am given an array of lines from a text file. They look similar to this, and will always be structured like this: Full Tue Aug 27 10:59:43 2019 1 ...
1 vote
1 answer
4k 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 ...
8 votes
2 answers
26k views

How to make in SSH private key from one line, three lines [closed]

i have ssh-key, something like this -----BEGIN RSA PRIVATE KEY----- my_super_secret_password -----END RSA PRIVATE KEY----- Of course this key does not work. When i am doing manual things, something, ...
3 votes
2 answers
2k views

How to add the filename as prefix to each line of the text file? (batch processing; subdirectories)

I have many .txt files with their filenames being different dates: 01.01.2010.txt 02.01.2010.txt ... Currently each file (e.g.: 01.01.2010.txt) looks like this: 0.351 XXX XXX XXX XXX 0.292 ...
2 votes
2 answers
1k views

sed insert a string into a matched line inside quoutes

I'm writing a shell script that modifies GRUB options: sed "/^GRUB_CMDLINE_LINUX_DEFAULT=/ s/$/ mem_sleep_default=deep /" /etc/default/grub This sed command matches the line ...
0 votes
2 answers
142 views

sed/awk - find match by one string and change different string on the same line

this should be easy question for most of you but for me. I need to perform some text operations above json a yml config files, which contains definitions of some channels - structure of every line is ...
3 votes
2 answers
5k views

How can I use grep to find the most frequently recurring errors in my log file?

I've got a PHP application that is generating large amounts of warnings and notices in the log file.. I'm fixing these one at a time. I would like to be able to fix the most frequently occurring ...
0 votes
2 answers
2k views

sed regexp for replacing xxx in define('DB_PASSWORD', 'xxxx');?

I'm looking for a regexp to quickly replace the password inside the following wp-config file, like so: define('DB_PASSWORD', 'xxxx'); Now the config file has many defines, so it essential to only ...
9 votes
4 answers
36k views

How to get all running process ids only?

I know that ps ax returns the pids 1 ? Ss 0:01 /sbin/init 2 ? S< 0:00 [kthreadd] 3 ? S< 0:00 [migration/0] All I need is to clean those strings, but I ...
1 vote
1 answer
2k views

remove single quote from all directory and file names

I ran a sed command recently and I mistyped the command (yes it happens). So now i have directory and file names that look like 'Call of Duty'. How can I recursively go back and rename all files and ...
-1 votes
2 answers
233 views

get string inside quotes with sed

I have a file with text like these: "id":1519539,"description":"xxxxxxxx","severity":"yyy","pasahelpdesk":null,"subSource":"","dateReception":{"timezone":{"name":"Europe\/France","timestamp":...
0 votes
2 answers
322 views

Extract text between 2 strings only if another string is present

I have a quit large XML file that I am trying to modify only certain lines of the file. The lines I want to modify will all contain in them. On those lines, I want to have only the text between 2 ...
0 votes
2 answers
1k 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
1 answer
60 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
1 answer
61 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
2 answers
260 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
3 answers
140 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 ...
2 votes
2 answers
2k views

How can I remove malware code in multiple files with sed?

I've this malware code in so many .html and .php files on the server. I need to remove them using sed -i expression search all files under directory /home/ find infected files remove the code by ...
1 vote
2 answers
11k 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 ...
1 vote
2 answers
492 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
1 answer
619 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
2 answers
2k 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
1 answer
4k 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
1 answer
85 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 |...
2 votes
4 answers
3k 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 ...
0 votes
0 answers
1k 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
2 answers
154 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 ...
1 vote
1 answer
278 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
3 answers
169 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
1 answer
41 views

sed search and add some sting

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

Recursively rename files using find and sed

I want to go through a bunch of directories and rename all files that end in _test.rb to end in _spec.rb instead. It's something I've never quite figured out how to do with bash so this time I thought ...
42 votes
5 answers
103k views

Using sed to remove both an opening and closing square bracket around a string

I'm running this command in a bash shell on Ubuntu 12.04.1 LTS. I'm attempting to remove both the [ and ] characters in one fell swoop, i.e. without having to pipe to sed a second time. I know square ...
0 votes
1 answer
406 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 ...
1 vote
2 answers
210 views

Wrangling sed to find and reformat login date (or, how to kill idle mosh-server processes)

I have an old method of killing idle mosh-server processes, which doesn't work on my new VPS. Here's the old method, which I run in root's crontab to clean up mosh processes that have been idle for ...
0 votes
2 answers
2k 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
3 answers
3k views

Using sed to prepend zero to four-digit numbers

I have a list of numbers, for example 1394 49020 344 34 4904290 2350 5 I am trying to prepend '0' to the four-digit numbers using sed, so the example above should give '01394' and '02350' and ...
0 votes
1 answer
208 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 ...