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
27 views

sed add a line after match that contains a new line

I have the following block. location /api { proxy_pass http://localhost:8080; } location /oauth2 { proxy_pass http://localhost:8080; } location /login { proxy_pass http://...
user avatar
0 votes
1 answer
25 views

sed replace is not replacing anything

sed -i 's/#DirectoryIndex index.html/#DirectoryIndex index.php /etc/httpd/conf/httpd.conf' which gives out the error sed: -e expression #1, char 57: unknown option to `s' I am trying to replace ...
user avatar
0 votes
1 answer
53 views

Failing string replacement in xargs command

I am trying to automatically create symlinks to directories and to replace a certain text string (foo) of the original name in the link name (bar). The name of the target directories may contain ...
user avatar
0 votes
2 answers
116 views

sed: -e expression #1, char 113: unknown command: `['

I was wondering why isn't this code working, it is simple but for some reason it's not working. WIREGUARD_TEMP_NEW_CLIENT_INFO="# ...
user avatar
0 votes
0 answers
111 views

Replace a string from the cat output

I need to replace a string with the string which is mentioned in a file abcd.txt in all files in a folder. For eg: I want to replace a string 'apple' with whatever the cat output of this file abcd.txt ...
user avatar
  • 67
5 votes
3 answers
795 views

Best way to remove text from the beginning of a huge file

I have a huge MySQL backup file (from mysqldump) with the tables in alphabetical order. My restore failed and I want to pick up where I left off with the next table in the backup file. (I have ...
user avatar
0 votes
1 answer
33 views

Can Linux do conditional judgment to insert the content at a certain line in Linux

Can Linux do conditional judgment to insert the content at a certain line in Linux? For example, I would like to add user "test" to /etc/sudoers to let it can switch to root: 1 # 2 # ...
user avatar
  • 151
0 votes
1 answer
165 views

sed: customizing config file header with a defined length?

I use sed to customize LXC container configuration files from the LXC host. That works well so far. When adjusting comment headers (hostname and date), there are aesthetic problems with the width of ...
user avatar
0 votes
0 answers
126 views

sed works fine from interactive shell but not from script

Trying to enable/disable xdebug on my php-fpm docker container. If I start an interactive shell using docker exec my_container bash then run: sed -i 's/^#zend_extension/zend_extension/' /usr/local/etc/...
user avatar
  • 161
0 votes
0 answers
21 views

sed behaviour depending on the file I apply it to

I have one file called test1.xml withe the following content: Hello how are you doing? And am trying to apply the following sed search and replace: sed -i 's/Hello //g' test1.xml And the file ...
user avatar
0 votes
0 answers
26 views

is there any representation for search in ansible.buildin.replace ... /string/ s/toreplace/newstring/g

im wondering if there is no representation for the sed string sed -i -E '/searchString/ s/toreplace/newstring/g' file in ansible.buildin.replace to replace only the 'toreplace' string in lines which ...
user avatar
  • 1
0 votes
2 answers
112 views

Awk script to filter text output to single line

I have a script that is giving me an output like this: ruby-devel is needed by software1 tcl is needed by software 2 python3 is needed by software 3 ocaml is needed by software 1 I'm new to awk but ...
user avatar
1 vote
1 answer
42 views

replace phases of fsck in fstab

I'm searching some way to replace fsck phases in my fstab file but only for line which contains specific path. currently fstab looks like that: /dev/mapper/vgroot-root / xfs defaults ...
user avatar
  • 13
1 vote
1 answer
209 views

SED config-file with single quote

I have a config file which looks like this: $this->db_host = 'localhost'; $this->db_port = '3306'; $this->db_name = 'database'; $this->db_user = 'root'; Im ...
user avatar
0 votes
1 answer
42 views

"grep" a group of lines

I am reviewing my mail traffic looking for large messages and sending these "finds" to the staff for removal or approval. Each message has four SMTP lines and I want extract just these ...
user avatar
  • 1
0 votes
2 answers
206 views

Piping nc to sed and evaluate datetime for each row

Could someone provide any idea, how could i pipe data from nc to sed (or awk, or anything) and evaluate and write to file a timestamp after each row? What i have: # cat /etc/systemd/system/ncserver....
user avatar
  • 3
-1 votes
1 answer
92 views

sed linux replace complex link

I am having this challenge to pass a link from a variable: InstallLocation=/opt/software/software.properties ReplaceeVar=http://localhost:1234/ab/cd/{company}/{employee}/ sed -i "s/...
user avatar
0 votes
1 answer
48 views

Finding a string and remove all contents between two delimiters

I have searched and I don't know what I'm doing wrong but I can't find an answer to this question. I have a file with all text stored as a single line. I am needing to find a pattern and remove all ...
user avatar
0 votes
1 answer
32 views

Multiply first column by variable depending on unit

I have du -sh output saved to txt file: 2.1G /home/x/sample/2GB/ 101M /home/x/sample/100MB/ ... What I want is to multiply each value in the first column by a value taken from variable ...
user avatar
0 votes
1 answer
25 views

Find all words after specific string

So, here's the thing. I have a file contains like this: LOG=123 HEY=BRO FOO=BAR LOG=124 I need the value of LOG= and an output like this: 123 124 I already tried using this command: echo "$LOG&...
user avatar
  • 3
-2 votes
2 answers
360 views

Linux Bash Scripting using grep sed and cut command to display ip address with port number

Can any one please help me I need a output of "192.168.1.1#53" by using these 'grep' 'sed' and 'cut' command mandatory in linux bash scipting in given below text. ;; Query time: 29 msec ;; ...
user avatar
-1 votes
1 answer
273 views

Mac sed not the same as linux

I have a bash script that I have used before on Linux and it runs fine on different distros, but not on a MAC. I am trying to read a file and then delete the current line. For some reason on Mac I ...
user avatar
2 votes
1 answer
2k views

Escape characters in systemd ExecStart fail

I have the following snippet to extract a value from a jenkins server jnlp config file. It works out of the box in the terminal but not as a unit. I want a unit so I can put the value somewhere and ...
user avatar
0 votes
1 answer
84 views

Shell script to remove quotes when using SED

I'm trying to change a line of syntax in a config file where the line looks like the following: host="192.0.2.100" I'm writing a script that would require input the user to change the ip ...
user avatar
0 votes
0 answers
26 views

Summarize first column same field

I have some datas with URL's and used network data. I made a custom file with these data's and i stuck last one step. What i have now: sevroland.api.url.com 488 www.logstach.url.com 42725 ...
user avatar
  • 1
0 votes
1 answer
268 views

How to change one line of code in a block of code from linux command line?

I have a change I need to make across multiple different sites and may need to make again in the future, so I'd like to put it in a shell script. Essentially I want to find a specific class block in a ...
user avatar
0 votes
1 answer
620 views

Issue restarting apache with cron / crontab ( Ubuntu 18.04)

I have a specific case where testing a new version of the software is being done at a specific time of the day so I have cronjob that should: Software is set in /var/www/html folders V2 and V3 ...
user avatar
1 vote
2 answers
46 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 | ...
user avatar
0 votes
1 answer
206 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 ...
user avatar
  • 137
2 votes
2 answers
145 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 ...
user avatar
  • 745
1 vote
1 answer
3k 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 (...
user avatar
  • 1,825
1 vote
1 answer
220 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 ...
user avatar
0 votes
1 answer
37 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 ...
user avatar
  • 267
0 votes
2 answers
910 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' ...
user avatar
2 votes
1 answer
9k 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 ...
user avatar
  • 501
0 votes
1 answer
134 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 ...
user avatar
0 votes
1 answer
93 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 ...
user avatar
0 votes
2 answers
239 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 ...
user avatar
  • 133
5 votes
2 answers
13k 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, ...
user avatar
  • 501
2 votes
2 answers
1k 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 ...
user avatar
2 votes
2 answers
549 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 ...
user avatar
  • 123
0 votes
2 answers
52 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 ...
user avatar
  • 93
1 vote
1 answer
1k 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 ...
user avatar
  • 417
-1 votes
2 answers
156 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":...
user avatar
0 votes
2 answers
89 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 ...
user avatar
0 votes
2 answers
590 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 ...
user avatar
2 votes
1 answer
48 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 ...
user avatar
0 votes
1 answer
37 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 ├─...
user avatar
  • 313
0 votes
3 answers
496 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 ...
user avatar
0 votes
2 answers
213 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: ...
user avatar

1
2 3 4 5 6