Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sed]

sed is a command-line stream editor for filtering and transforming text.

5
votes
1answer
182 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
5
votes
1answer
732 views

Why is sed changing permissions of a file on a cifs mounted share?

I have an Arch linux machine that uses the following fstab entry to mount a share: //192.168.3.1/Documents /mnt/ cifs credentials=/home/tal/.smbcredentials,rw,x-systemd.automount,iocharset=...
3
votes
1answer
102 views

Use sed to keep only parts of a file and reorder it (based on textWrangler grep syntax)

I want to edit a file called trial.fastq with the following format: @NAME123.15.1 15 length=151 GTAGCNTACGGGAGGCAGCAGTGGGGAATTTTCC +NAME123.15.1 15 length=151 AAABB#>>AABDGCEGGGFGGGHHHGGGFHHGHH ...
3
votes
1answer
1k views

Modify filenames in Makefile

For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with ...
2
votes
1answer
45 views

Script to add a block in a few hundred files

I want to add the following lines if ($http_user_agent ~* "somewebsite" ) { return 444; } to all my vhosts in NGINX as follows server { location / { want_to_add_those_3_lines_here } } ...
2
votes
1answer
40 views

Add (true || … ) to a function using sed

I quickly want to patch a huge library by adding true || in front of every function call. Example input: if function_a(some_parameters) && function_b would turn into if (true || function_a(...
2
votes
1answer
159 views

Why is sed failing to follow collate order?

On this command: $ echo "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | > sed 's/[a-z]//g' ABCDEFGHIJKLMNOPQRSTUVWXYZ It seems correct, doesn't it? However, the locale in effect is ...
2
votes
1answer
166 views

Formatting and fill missed data based on column

I have the data in this format and I want to sort it based on the label in each column. Would want to replace the missing field by a comma (,) like shown below 2018-03-13 02:09:12,AB=123,BC=6,CAB=Jax,...
2
votes
1answer
205 views

extract fasta entries from list using while read

I have 28 files that each have ~14,000 "entries". A single entry consists of a header, denoted by >string, a newline, and then a sequence which is a string. Each entry has variable length sequence/...
2
votes
1answer
781 views

how to capture the latest kernel version from grub.conf

How can I capture the latest kernel version from grub.conf ( in case default=0)? For example the latest kernel from the file is 2.6.18-409.el5 # all kernel and initrd paths are relative to ...
2
votes
1answer
837 views

Highlight nth column of ps output

I'm trying to find the best way to highlight a specific column of some output. Specifically, I'm trying to highlight the 9th column (which is %cpu of the command: ps -eo pid,ppid,time,user,tty,%cpu,%...
1
vote
1answer
113 views

pass arguments to the date command in LHS of sed

I need to convert a date string from the form: "Jan 07, 2016 12:12:12 EDT" (from a nessus report) to a simple 2016-01-07. I have the match logic solved in sed (and python and awk) and the conversion ...
1
vote
1answer
53 views

Output log lines between startTime and endTime

Given I have log file app.log with contents: 2018-08-29 07:43:17.123-0500 CDT [osb_02] [[ACTIVE] ExecuteThread: '14' for queue: 'weblogic.kernel.Default (self-tuning)'] INFO - [OSB Tracing] Outbound ...
1
vote
1answer
408 views

Replace a binary block within a large file

I have a partition image that contains a 1MB file populated with random data, and I would like to replace the contents of that file with another 1MB file populated with different random data. I have ...
1
vote
1answer
598 views

How to remove newline character within a column in a tsv file?

I need "This contains newline" in one row, newline from the column2 and column4 need to remove. nb: For your understanding the data I upload an image if you want I will upload the text content "...
1
vote
1answer
425 views

Multi-line String Pattern Matching, Insertion and Deletion with sed or awk

I'm trying to write a script to automatically update my .ssh/config. Basically it's an ssh management tool that will add an .ssh/config entry for an input computer, user, etc. Question: Are there ...
1
vote
1answer
798 views

Extract intermediate certificate from openssl s_client output

I'm looking for some easy way to get intermediate certificate details from openssl s_client. I can just pipe output to openssl x509 but it takes leaf cert first. I came up with this script, it works ...
2
votes
0answers
83 views

sed behaves strange on android tablet

Hi I'm new to using sed When I type: echo day | sed /s/day/night/ the output is: nightday In other words, it just appends the entire line after the substitution. I am using a Samsung Galaxy Tab ...
2
votes
0answers
184 views

use gff2fasta instead of a bash script to get parts of DNA sequences out of a full genome

EDIT and a solution Because my original question was badly phrased and I was trying to re-invent the wheel I am answering my own question now (maybe it helps someone else): gff2fasta is a tool which ...
2
votes
0answers
749 views

RE error: repetition-operator operand invalid

I'm getting this error RE error: repetition-operator operand invalid On FreeBSD sed, using csh. Command is: sed -rn 's/.*?VIEW ([^\s]+?) (AS .*?)\s([^\s]+?)\s([^\s]+?)/DROP VIEW \1;\nCREATE VIEW ...
2
votes
0answers
265 views

sed stdin behaviour

Using sed for a direct stdin treatment of data, I expect that a line is treated after the enter. This is what happens when I test on CygWin or Linux but on my AIX, a second new line is needed to treat ...
1
vote
0answers
58 views

sed command is replacing the replaced text?

I am writing a bash script to rename icons. Specifically I am trying to change "icon-close-m" to "icon-close icon-size-medium" in HTML files. (though it could contain any substring besides "close", as ...
1
vote
0answers
84 views

How to improve this 'sed' search & replace command?

How to search and replace recursively through multiple files in a directory, using essential tools installed in mostly any Debian/Ubuntu machine? There are multiple answers in Stack* where to find ...
1
vote
0answers
27 views

Merge 2 files based on the 2nd column of each and overwrite common lines in first file

I have a couple of CSVs'. file1 has a large number of URLs and file2 also has a URL field which have to be matched with file1. Now file1 has a couple of columns I need to add to file2. I have managed ...
1
vote
0answers
30 views

Sed command writes the expression in outer ifmodule

my config file has this <IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule> I want to change "index.php" to "index.temp" I ...
1
vote
0answers
43 views

Cannot install Sed in tools directory, Permission Denied

I am building Linux From Scratch. Here's the error I faced during installation of sed. /tools/bin/install: cannot create regular file '/tools/bin/sed': Permission denied Because of this I cannot ...
1
vote
0answers
77 views

Sqlite: replace a string modelID1/modelID2/modelID3 with name1/name2/name3/

My goal is to read the macOS Photos.app database to find out the paths of the included photos. The album and the parent folder whose name is in the RKFolder table can be determined for each photo. ...
1
vote
0answers
53 views

Use sed to fix weird symbols on tex file generated by publish function from miscellaneous Octave package

I have an Octave code that among other things outputs: (x - 5)⋅(x - 4)⋅(x - 3)⋅(x - 2) ─────────────────────────────── 24 When using publish function from Octave miscellaneous ...
1
vote
0answers
461 views

Getting a range of lines between timestamps from /var/log/messages

I want to get all lines between two timestamps from /var/log/messages. I only have start time which I provide to my script as input. The script then should get me all the lines till next day as output....
1
vote
0answers
460 views

Edit /etc/lvm/lvm.conf and add a new global filter

I want to replace the below string with new string in file test.cfg. There is only 1 occurrence of this string in the entire file. Line in the test.cfg file where this string is present: ...
1
vote
0answers
137 views

How to change the first line only on certain files in a folder using sed

I'm doing this on Windows Vista 32 bit version. I have 2 folders on my desktop : folder_a (with sed.exe) and folder_b with these files : sand.txt tree.txt chair.txt xyz-fork.txt xyz-spoon.txt If I ...
1
vote
0answers
97 views

Dictionary - synonyms

I have czech czech-finnish dictionary and I have two czech synonyms in one row. Example: záchod (m); toaleta (f) WC; käymälä; miestenhuone; naistenhuone; vessa Synonyms are divided by semicolon and ...
1
vote
0answers
1k views

How to redirect linux command outputs to specific row and column in csv?

I'm working on Unix Build post documentation process, I have a CSV file to be filled in and uploaded for every new build, to ensure the servers are build as per the original request. The CSV file ...
1
vote
0answers
73 views

Using sed to unlock fields in a pdf

At my job we regularly unlock the fields of pdf files in order to edit them using this sed script in a .bat file: type %1 | sed -E 's/(.*\/T\([a-zA-Z0-9]*\).*)\/Ff 1(\/?.*)/\1\/Ff 0\2/' | sed -...
1
vote
0answers
643 views

OpenWRT missing OD (octal dump)

I have a bash function using od command. Now I'm trying to run in on OpenWRT and see that in has not od. Also can't find it using install from opkg, because I can't find it. Is there a possibility to ...
0
votes
0answers
20 views

macOS High Sierra “log show ” ouput

The log show command output from a macOS High Sierra is detailed below: **Command 1** log show --info --predicate 'eventMessage contains "system boot:"' log: warning: ./system_logs.logarchive ...
0
votes
0answers
36 views

sed command to insert between two strings that are returned from another sed command

I have a YAML file that's about 25K lines and I have about 450 instances where I need to insert between two specific lines. Here's an example of the file entries: - changeSet: id: ...
0
votes
0answers
55 views

Rotation script for xorg tablet (x230t in my case) with pen(digitizer), touch and eraser. Any optimizations?

Maybe somebody has some optimizations to this code or sed expressions? Just bourne shell, sed, xrandr and libinput rotation script: % cat rotate.sh #!/bin/sh if [ "$#" -lt 1 ] ; then echo "...
0
votes
0answers
28 views

URL match in a file using shell script

I need to write a unix shell script Lets say i have a URL maps.google.com and file1.txt as below: google.com,Id=0 m*.google.com,Id=1 m*r.google.com,Id=2 map*.google.com,Id=3 *p*.google.com,Id=4 *aps....
0
votes
0answers
36 views

convert my csv file output to html table with heading bold and and send email using post fix & also want to change the font to calibri

for i in $(cat HPE_FRAMES_IP); do ssh Reports@$i showsys | awk '{print $2","$5}' ; ssh Reports@$i showpd -degraded -failed | awk '{print $1","$2","$3","$5}' ; done | grep -v "MiB" | grep -v "total" | ...
0
votes
0answers
188 views

replace placeholders in file with the actual environment variables using sed

I have a template file like this: export const environment = { api: { url: '$API_URL', key: '$API_KEY', } } and I was trying to replace the actual placeholder values like this: sed 's/$\...
0
votes
0answers
38 views

How do I extract only certain parts of ffmpeg's standard output as it processes a file?

I want to enter a command that only shows these two lines of ffmpeg's output and I want to see it as it processes a file: from 'input_file.mkv': frame=172534 fps=4622 q=-1.0 Lsize= 8319963kB time=01:...
0
votes
0answers
56 views

How can I parse through a log file, extract certain values and construct a tab or comma delimited text file?

I am trying to convert a pre-formatted section within a log file into a comma or tab delimited tabular view. Here's a sample section contained in the log file: Appliance-01> home Appliance-01>...
0
votes
0answers
72 views

sed/awk/grep/cut: multiply a number in an xml-attribute by factor of ten

I would like to multiply the attribute in viewBox of svg-files by a factor of ten. I want to change <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" version="1.1"> to <svg xmlns=...
0
votes
0answers
114 views

Why sed s acting differently on RedHat vs Mobaxterm using regexp?

I have a .txt file which includes "junk" characters, emojis. Example: 12/11/2015, 12:07 - 5465464: Super Wakkka👏🏻 12/11/2015, 12:30 - 89415: qwertz svima, nadam se 😊 12/11/2015, 12:34 - 55698742: ...
0
votes
0answers
70 views

Replace all contiguous newline chars to a single comma

I have this git log command: const command = [ `git log ${branch} -${count} --grep="${grep}"`, ` --pretty=format:'{"subject":"%s","body":"%b","commit":"%h","sanitized_subject_line":"%f",`, ...
0
votes
0answers
199 views

Bash variables in sed including an end of line condition

I have a bash variable replacement in sed, where some information at the end of line of the 3rd line for example should also be matched. a=3 #line no b=tap #pattern c=9 #replacement data sed "${a}s/$...
0
votes
0answers
130 views

How to restore sbatch array job output file names to their original names

In order to submit array jobs using Slurm, I've renamed hundreds of files with incremental numbers using the following command: COUNT=1 for file in ./*; do mv "$file" "${COUNT}" let COUNT++ ...
0
votes
0answers
523 views

tmux status bar path customization with sed

On the server I connnect to my home path is like this:/home/junk1/junk2/user. I can use the sed command pwd | sed -e 's|^/\([[:alnum:]]*\)/[[:alpha:]]*/[[:alpha:]]*|/\1|' to shorten the directory path ...
0
votes
0answers
965 views

Dynamic search and replace in Ksh

Machines at work follow a constant naming pattern: host[domain]_[id] where [domain] is either "d" for dev machines and "p" for production machines, and [id] is a 2-digit string that is different for ...