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
1
vote
2answers
30 views

Unix Sed time range parsing issue

I have Hybris SAP application with console log. The log format looks like this INFO | jvm 1 | main | 2020/05/28 17:17:19.969 | <String>timestamp</String> INFO | jvm 1 | ...
0
votes
1answer
16 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
2answers
43 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 ...
0
votes
1answer
31 views

Have sed -i output to stdout the way just sed does

When I am running sed operations on a file, for example: sed 's/this/that/' /my/file.txt The output is displayed on stdout. However, when I apply the changes in place with -i there is no stdout (...
0
votes
0answers
14 views

Linux sed: Extract value of a key in a string

I scoured the internet for a quick solution as i have less time to invest in reading the basics of regular expression as of now due to time constraints and thus here i am with the question below. ...
0
votes
0answers
21 views

Apache2 - CustomLog fails with incorrect argument when piped trough sed

I am using the httpd docker image for apache, and trying to add a CustomLog command to the conf that performs a regex on the acess-log before insertion by piping it trough sed. I am using the ...
0
votes
0answers
11 views

Tool for Previewing `sed` Expressions

When working with regex to do replacements or captures I often use webapps like rubular or regexr. Is there a similar webapp or tool for testing sed expressions? Thanks.
1
vote
1answer
68 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
1answer
14 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 ...
0
votes
2answers
55 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' ...
0
votes
1answer
1k 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
1answer
125 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
1answer
61 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
2answers
121 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 ...
2
votes
2answers
2k 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, ...
2
votes
2answers
462 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
2answers
57 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
2answers
39 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 ...
1
vote
1answer
164 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
2answers
83 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
2answers
40 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
2answers
202 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
38 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
1answer
28 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
115 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
2answers
150 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
97 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
151 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
137 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
33 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
441 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
114 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
53 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
34 views

sed search and add some sting

======KVM 虚拟化手册====== =====简介===== =====安装和配置kvm虚拟化===== ====检查是否支持KVM==== ====安装kvm虚拟化平台==== ====配置nested virtualization==== ==== 配置网络==== ====重启系统并检查相关配置==== =====virsh创建 & 安装虚拟机===== ====...
2
votes
4answers
558 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
80 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
72 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
1k 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
68 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
199 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
2k 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
194 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
86 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
666 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
108 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
423 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
515 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
607 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
250 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
1k 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
2 3 4 5