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.
279 questions
0
votes
1
answer
67
views
Format and filter ibm-mq queues
I need to display each IBM MQ Queue Manager queue along with its depth.
I can do this with a command like echo DISPLAY QLOCAL(QE*) WHERE(CURDEPTH GE 0) | runmqsc QMNAME.
The output is similar to this:
...
0
votes
1
answer
104
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
0
votes
1
answer
68
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/...
0
votes
1
answer
331
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 ...
0
votes
2
answers
324
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....
1
vote
2
answers
2k
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,...
2
votes
2
answers
298
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: ...
0
votes
1
answer
558
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 ...
-1
votes
1
answer
174
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 ...
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 ...
0
votes
1
answer
118
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 ...
1
vote
1
answer
276
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 ...
0
votes
1
answer
886
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 ...
0
votes
1
answer
9k
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://...
0
votes
1
answer
478
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 ...
0
votes
1
answer
844
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 ...
0
votes
2
answers
932
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="# ...
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
...
5
votes
3
answers
863
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 ...
0
votes
1
answer
57
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 # ...
0
votes
1
answer
179
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 ...
0
votes
0
answers
55
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 ...
0
votes
2
answers
429
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 ...
1
vote
1
answer
155
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 ...
1
vote
1
answer
496
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 ...
0
votes
2
answers
872
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....
-1
votes
1
answer
457
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/...
0
votes
1
answer
376
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 ...
0
votes
1
answer
77
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 ...
0
votes
1
answer
232
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&...
-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
;; ...
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 ...
2
votes
1
answer
6k
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 ...
0
votes
1
answer
181
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 ...
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
...
0
votes
1
answer
399
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 ...
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 ...
1
vote
2
answers
101
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
1
answer
398
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
245
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 ...
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 (...
1
vote
1
answer
924
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
79
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
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'
...
2
votes
1
answer
17k
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
217
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
1
answer
248
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
2
answers
720
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
...
8
votes
2
answers
28k
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
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 ...