Skip to main content

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

using sed to replace a string between quotes '12h' by '3h'

I am trying to use sed to replace a string like '12h' by '3h' sed -i 's/length_s = '12h'/length_s = '3h'/g' my_files but it didnt work
Rabah's user avatar
  • 1
0 votes
1 answer
56 views

Change item in Apache configuration file with `awk`

I am not an expert with awk tool. I must miss something obvious... What works so far: [root@checkmk ~]# awk '/^[[:blank:]]*SSLCertificateFile/ {gsub(/\/etc\//, "/not_etc/")} 1' \ /etc/httpd/...
user148942's user avatar
0 votes
1 answer
226 views

sed + delete all comment lines and when line match specific word

I created this sed in order to delete the comment lines lines from fstab ( comment can ne with begin of space or TAB etc ) sed '/^[[:blank:]]*#/d' /etc/fstab in my case I want to add also the ...
King David's user avatar
0 votes
2 answers
166 views

Bash script : Print all lines between two pattern in variables with slashes

I have a directory that looks like so : /path/to/files/data-file.1 /path/to/files/data-file.2 /path/to/files/data-file.3 /path/to/files/data-file.4 /path/to/files/data-file.5 /path/to/files/data-file....
Ror's user avatar
  • 343
1 vote
2 answers
1k views

How to remove all lines with the same public key from known_hosts?

Let's imagine the following scenario. I have an host key ABCDEF1234 for a given hostname, so my known_hosts file looks like this (unhashed version): example.com ssh-rsa ABCDEF1234 Now I connect to it,...
shodanex's user avatar
  • 242
2 votes
2 answers
264 views

Convert lscpu output to row based format in excel/csv table format

I have the below data (lscpu output) for 1000 servers and I want the same in excel but in row format and not as in command output in columns 1.2.3.4 CHANGED Architecture: ...
Loki's user avatar
  • 21
0 votes
1 answer
450 views

sed not working on large files. Any other options available?

Trying to insert a line feed on large files in UNIX when a text string matches. Any file around 1GB or less, it works. Anything over that size, it does not complete the replace. It appears to do ...
TimBurke's user avatar
-1 votes
1 answer
129 views

Copy/Move Entire Line To End Of The Line Above

I have a file that looks like the following: /path/to/a/very/long/path 0 0 0 0 0 0 I need to move the line starting with a number (this can be any value not necessarily 0) to the end of the ...
djc72uk's user avatar
  • 33
4 votes
1 answer
2k views

How to correctly escape single quotes in AWK

It isn't clear exactly what more needs to be escaped in the following macro to allow it to be used with awk or sed on FreeBSD. define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl Here is an awk command ...
Utkonos's user avatar
  • 388
0 votes
1 answer
114 views

PHP Serialize AWK command speed up?

I've built an SQL migration script that will replace text in a MySQL dump file. Replacements would be easy with sed, but we must account for special serializations (PHP Serialize). The code below ...
Richard Tyler Miles's user avatar
1 vote
1 answer
254 views

awk pattern search with file input to search in another file

I am looking for some hints, how I could achive a better, more elegant, efficient solution. So I've got a file containing a list of names. names.txt: Doe John del Super Mario van Hoppity Jenny van der ...
zippy-flop's user avatar
0 votes
1 answer
756 views

how can I extract a Version number from a website with curl and grep / sed?

I want to get the latets version number from this website: https://www.mailpiler.org/wiki/download so I do a curl to get the content and then just use a pipe to search for the string using grep curl ...
helpmenicely's user avatar
0 votes
1 answer
8k 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://...
Sputnikk23's user avatar
0 votes
1 answer
433 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 ...
alex foxton's user avatar
0 votes
1 answer
769 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 ...
Ric Treepusher's user avatar
0 votes
2 answers
863 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="# ...
yz7Ql4rxq7gY78evJ4Ao's user avatar
1 vote
0 answers
1k 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 ...
Am3Y's user avatar
  • 77
5 votes
3 answers
852 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 ...
Christopher Schultz's user avatar
0 votes
1 answer
49 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 # ...
ITnewbie's user avatar
  • 171
0 votes
1 answer
177 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 ...
questor's user avatar
0 votes
0 answers
52 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 ...
Milos Cuculovic's user avatar
0 votes
2 answers
411 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 ...
Emersonjr's user avatar
1 vote
1 answer
133 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 ...
MiK's user avatar
  • 13
1 vote
1 answer
479 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 ...
friedulman's user avatar
0 votes
2 answers
749 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....
M.Ch.'s user avatar
  • 3
-1 votes
1 answer
424 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/...
Rado Ratko's user avatar
0 votes
1 answer
357 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 ...
Chris Spangler's user avatar
0 votes
1 answer
65 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 ...
DisplayName's user avatar
0 votes
1 answer
167 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&...
Azikun's user avatar
  • 3
-2 votes
2 answers
1k 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 ;; ...
hemanth singamala's user avatar
0 votes
1 answer
1k 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 ...
user2236794's user avatar
2 votes
1 answer
5k 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 ...
eignhpants's user avatar
0 votes
1 answer
174 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 ...
Peter Yates's user avatar
0 votes
0 answers
30 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 ...
TDex's user avatar
  • 1
0 votes
1 answer
394 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 ...
TBridges42's user avatar
0 votes
1 answer
2k 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 ...
Perovic 's user avatar
1 vote
2 answers
91 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 | ...
Vladimir Knysh's user avatar
0 votes
1 answer
369 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 ...
Kalib Zen's user avatar
  • 137
2 votes
2 answers
229 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 ...
lonix's user avatar
  • 978
4 votes
1 answer
7k 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 (...
emmdee's user avatar
  • 2,317
1 vote
1 answer
821 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 ...
rs232's user avatar
  • 105
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 ...
user99201's user avatar
  • 307
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' ...
Siju George's user avatar
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 ...
Piduna's user avatar
  • 571
0 votes
1 answer
186 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 ...
Ron Russey's user avatar
0 votes
1 answer
247 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 ...
Ron Russey's user avatar
0 votes
2 answers
648 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 ...
Kevin's user avatar
  • 133
8 votes
2 answers
27k 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, ...
Piduna's user avatar
  • 571
3 votes
2 answers
3k 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 ...
user3200534's user avatar
2 votes
2 answers
2k 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 ...
Lau's user avatar
  • 123

1
2 3 4 5 6