Questions tagged [sed]
sed is a command-line stream editor for filtering and transforming text.
6,740
questions
0
votes
0
answers
10
views
How to retrieve data from a logfile between time stamps in a bash script
I have a logfile that i am trying to 'grep' data out of via a bash script. The data i am specifically after is all lines between two timestamps (including the top timestamp) that have the pattern &...
0
votes
2
answers
18
views
Append a character at the beginning of next line matching the pattern throughtout the file
Test file:
cat Test.txt
#EXTM3U
#EXTINF:100
a.flac
#EXTINF:20
b.flac
Expected Result
cat Test.txt
#EXTM3U
#EXTINF:100
#a.flac
#EXTINF:20
#b.flac
Experiment 1
sed -e '/^#EXTINF/a #' Test.txt
#...
0
votes
0
answers
58
views
Extract identifiers and corresponding brackets among overlapped brackets
I have some files contained identifiers as below:
B#205918
A#273075
E#554065
Eg. sample of file1:
((((A#273075,A#273116),((A#224325,A#192952),A#243232)),(((E#7955,E#7165),E#6239),E#4530)),(((((E#3075,...
1
vote
0
answers
25
views
Rework sed for vim's errorformat for circom compiler
compiling ciruits and intend to use quickfix. but the compiler output was not in standard format ... so tried parsing
Need help
fixing the sed command
preping the output for error format so that i ...
0
votes
2
answers
42
views
Sed script to AWK
I don't do this often, and when I do it is always time sensitive. I have the sed script below that extracts a number pattern from over a million files. I need to pike this to AWK, so when the ...
0
votes
1
answer
18
views
Not obtaining lazy evaluation using sed
I would have expected 'a' for this, why 'a:b'?
$ echo "a:b:c" | sed -E 's/(.+?):.+/\1/'
a:b
1
vote
1
answer
50
views
How to use find and sed to replace certain sentences in files
I am using find and sed commands to find and replaces the occurrences of certain sentences in the whole directory with some other sentences.
For example if I want to replace all occurrences of the ...
0
votes
0
answers
36
views
change the bash output with stream editing [duplicate]
If I call bash like this: bash|sed 's/a/b/g' every time bash outputs an 'a' it is replaced with a 'b'
$ bash|sed 's/a/b/g'
$ echo aaa
bbb
$ exit
However if I add additional substitutions like so:
...
2
votes
2
answers
84
views
Replace matched regex in file content with variables
I would like to do the following
Search file content with pattern (^[ \t]*services:[ \t]*)
If found, replace the pattern by a String (in variable)
Else, append the String (in variable) at end of file
...
1
vote
2
answers
39
views
Couldn't get sed to match a group
I'm trying to do the below:
echo "/Users/anon/Applications/Chrome Apps.localized/Spotify.app" |
sed -E 's:([^\/]*$).*:\1:'
which I assumed would capture Spotify.app and replace the entire ...
2
votes
3
answers
114
views
awk/sed split a cluster file in to multiple files
I have a cluster fasta file (called file) which looks like:
>1AB2
>1AB2 AA
NWWIEUNJRNIBGOWNGIOWGRBIGBRGRIOWGI
NCIDHFR8EHGBVPIWOBGIGRI
>1AB3 AA
WNIOREHUEBRGOUERGHBERGIORBGREUGEGO
...
-2
votes
4
answers
128
views
sed or awk: replace only the n-th occurence of a string
How to write a sed (or awk, or both) which will take the following:
echo '1 aa 2 2 3 bb 5 bb 2 5' | sed/awk ...
And only replace the n-th occurrence of a string? For example the 3rd occurrence of 2 ...
2
votes
2
answers
91
views
Replace digits and then characters pattern with sed
I have a file like below:
some
arbitrary number of
leading
lines
a prefix followed by wmd v0.0.0-20220406135915-ce5e3ee6c6bf
some
trailing
lines
This is only an example of what the file could look ...
2
votes
8
answers
312
views
awk filter rows that only consist a single letter
I have a file (file1) that looks like this:
ROW 1 AA 120 APFGHKDESFNNJFHGRIHJASFGNSKDHFIXXXXXX
ROW 2 AA 234 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ROW 3 AA 122 XXXXXXXXXXXXXXXXXXXXX
ROW 4 AA 89 ...
0
votes
1
answer
54
views
Return content between corresponding brackets
I have a file with all type of brackets {}[]()- nested, open and close appropriately. I would like to return the content within the matching square brackets after the string (text:). The content of ...
3
votes
5
answers
271
views
Bash: sed or awk rewrite of numerical sequence
How to write a sed (or awk, or both) which will rewrite the following:
echo 'v100 v201 v102 v300 v301 v500 v999 v301' | sed/awk ...
to this output:
v1 v2 v3 v4 v5 v6 v7 v5
i.e. each subsequent vx ...
-1
votes
2
answers
41
views
Extracting data from a file with a regular expression in sed
How can I use sed to extract f607b9ab-1452-4758-b047-6b620591211b by using cmrepo-222-02 as my reference?
["+--------------------------------------+---------------+----------+------+-------------+...
1
vote
4
answers
54
views
Split the line into next line after a matching pattern
In the input file shown below, I am trying to find the string job_type and move the it to the next line if it matches job_type.
I tried this, but it is not working:
sed "s/[A-Z][a-z]*job_type:/\...
0
votes
3
answers
65
views
How to add column based in the second line match using SED or another command?
I have the following lines result from zcat command
1 - URL Template: https://www.test.com
2 - Response: <200 OK,{Server=[nginx], Date=[Wed, 11 May 2022 01:05:06 GMT], Content-Type=[text/html; ...
0
votes
1
answer
37
views
Trying to do a perfect sed replacement
I am trying to do a sed replacement which I am currently doing with two commands. I can't figure out how to combine the two commands together so that it replaces the words correctly in one go.
My role ...
0
votes
5
answers
91
views
How to ignore all text containing special character more than once?
Sample Input:
apple_ig
rabbit_cat_ig
dog_ig
bird_duck_ig
orange_ig
goat_ig
Expected output:
apple_ig
dog_ig
orange_ig
goat_ig
I need to ignore all data that contains underscore _ more than once in ...
-2
votes
3
answers
61
views
How to remove forward slashes from file in unix shell using sed? [duplicate]
I have the following file :
/
/FUSE
//
Bank S.A / N.V
/F
I want to remove all forward slashes (/), so that the result looks like this:
FUSE
Bank S.A N.V
F
How to do so using sed? Ive tried using ...
0
votes
2
answers
66
views
How to replace all occurrences of a sequence starting with a given string to the next appearance of a symbol?
I would like to edit a huge single line file with thousands of occurrences of some string 'string_string': until the next appearance of a comma , (including this comma) and removing those occurrences ...
-1
votes
2
answers
62
views
How can I add space after filename of grep output?
I am using grep to search matching patterns inside files, and copy its filename from the output. Since I do this operation a lot I may end up copying : as well. Hence is it possible to add two space ...
0
votes
2
answers
78
views
sed command to fix concatenating two string literals
I'm looking for a sed (or other Unix utility) command to find all instances of two string literals being concatenated, such that the command will replace these concatenations with the corresponding ...
0
votes
1
answer
34
views
How to upgrade sed on RHEL 8?
I'm on a RHEL 8 system and by default sed 4.5 was installed.
[root@192 ~]# rpm -qf `which sed`
sed-4.5-2.el8.x86_64
[root@192 ~]#
Since I want to use the --debug option to debug some sed commands, I ...
0
votes
2
answers
45
views
sed or other equivalent for grep with vfF
RHEL6.10 , gnu grep 2.2
grep -vfF stem.txt source.txt > filteredoutput.txt
stem.txt has unique 13 digit numbers.
source.txt is fixed length (400) data file where the 13 digit field value starts at ...
0
votes
4
answers
74
views
Finding max row with highest value for a particular country in a csv file
I have a .csv file with entries like
Location,Indicator,Period,First Tooltip
Afghanistan,Malaria incidence (per 1 000 population at risk),2018,29
Afghanistan,Malaria incidence (per 1 000 population at ...
0
votes
3
answers
86
views
Delete line in each text files if the first field value is greater than 400
I have a large number of txt files. the format of each txt files is similar to this
200 0.2 0.1 0.5 0.4
500 0.4 0.9 0.9 0.1
I am trying to delete each line in each txt file that has the first field ...
0
votes
2
answers
46
views
sed delete specific row
Delete the string except for the beginning of NM, how should it be written with sed
input_file
NF
NM_001708.2(OPN1SW)
NM_000374.5(UROD)
NM_000235.4(LIPA)
NM_021828.5(HPSE2)
HPSE2, EX8-9DEL
HPSE2, ...
2
votes
1
answer
137
views
replace character only when it's not inside curly braces (sed, awk, tr, ...)
I have a string called "desktops" that look like this:
desktops="1 2 %{F#990000}3%{F-} 4 5 6 7 8 9 0"
The 6 digits after the "#" represent an RGB color, so the 3rd ...
0
votes
1
answer
27
views
Cut last value of a string [duplicate]
My data is like (a.txt)
allheartweb.com
whoisdatacenter.com
domainsanalytics.com
covercian.co.uk
I want to extract all TLD from there
My code is
cut -d "." -f 2 a.txt
its show me
com
com
...
0
votes
1
answer
54
views
Replace exact strings in a file based on a list of strings and a list of corresponding replacements,
I'm trying to do a dictionary based search and replace, but i'm having trouble figuring out how to make it case sensitive/exact match, but it is proving quite difficult.
I have three files, fileA is ...
-1
votes
1
answer
55
views
How to remove only 1 line with a certain string
Hi i have a question i have searched everywhere but i cant find it.
I want to use the sed command to remove a line containing a certain string. In the text file there are more lines with the same ...
0
votes
3
answers
105
views
Replace a timestamp Base64 value in a file
I have a problem, I have a file test.txt that has a content like this:
dn: serv=CSPS,mscId=167e48dc2b7a42d4acce611c8b477262,ou=multiSCs,dc=three
structuralObjectClass: CP1
objectClass: CP1
objectClass:...
5
votes
5
answers
372
views
If column has multiple values, copy line with each value separately
I have a file with the following format, each column separated by tabs:
C1 C2 C3
a b,c d
e f,g,h i
j k l
...
Now I need to have the number of lines according to the number of values ...
0
votes
2
answers
64
views
How to replace the character in one column at the position indicated by another column with the string in a different column
I am rather new to bioinformatics (this is my first post!) and I would appreciate some help on task that has me stuck.
I have a Tab-delimited data table with three columns:
AATTCTTGCA 4 [A/T]
...
0
votes
1
answer
45
views
Use awk or sed to capture & parsing text
I've some text output like the following:
+-------------------------+-----+--------------------------------+--------------------------------------------+
| Site | SSL | URL ...
-4
votes
1
answer
54
views
Please help me in figuring out What does this command do?
I saw a command to fix issues while running cron jobs on stackoverflow.
https://stackoverflow.com/questions/21926465/issues-running-cron-in-docker-on-different-hosts
I am ntsure what exactly this ...
0
votes
1
answer
53
views
Include csv headers with sed [closed]
I have an csv file that looks like:
id, name, nationality
1, Maria, ESP
2, John, NED
3, Alice, DEN
I am building a document script.sed that executes different sed expressions like this:
s/ESP/Spain/g
...
0
votes
0
answers
19
views
awk or sed - find and replace in multiple files according to a key [duplicate]
I have hundreds of files in which I need to make various replacements - and those replacements are not the same in all of the files. For example, I want to replace:
WinEventLog with Windows
SysMon ...
0
votes
5
answers
131
views
Sed to replace text that comes after match
I was working it with awk, and keying on $1 $2 fields, but awk would act differently depending on whether the FieldSeperator ($match) starts the line, or had a blank before it, or didn't have a blank ...
0
votes
1
answer
30
views
reload the i3 conf in a script
i am writing a script to quick change the mod key of i3
conf0="/home/myuser/.config/i3/config"
case "${1}" in
(alt) key=Mod1 ;;
(win) key=Mod4 ;;
(*) printf "Invalid ...
0
votes
1
answer
55
views
How can sed replacement string be a command's output?
Below sed command helps add text Hello to the end of each line of the input
<complex_query> | sed "s,$,Hello,"
Output:
myvar1: Hello
myvar2: Hello
I now wish to have the output of ...
0
votes
2
answers
101
views
split string using a substring as delimiter and get the later part
Here is my string LIBRARY_TRGT_CANV,CANV_MATCH<anything>
I wish to get all the text after last occurance of our delimiter which is _TRGT_:
Desired output:
CANV,CANV_MATCH<anything>
------ ...
0
votes
1
answer
41
views
Need help Formatting a file having key: value [duplicate]
I have a file having the below values:
cat data.txt
server1: 'calv'
server2: 'anot'
log: '/u/log/1'
server3: 'calv'
server4: 'anot'
server5: 'secd'
server6: 'calv'
LIB_TRGT_calv,anot: '/tmp/hello.txt'
...
0
votes
3
answers
64
views
bash insert backslash for every slash in string
I have a string that is a path:
/tmp/something
I need to escape the forward slashes with backslashes:
\/tmp\/something
How can I do this? Maybe sed?
Please point me in the right direction.
0
votes
3
answers
76
views
How to use crossplatform/standard sed between linux and mac?
Hi I have one script that was running inside makefiles for project deployments.
I use sed inside it to capture environment and project name from input string and in ubuntu works great.
This simple ...
0
votes
2
answers
105
views
Using a regex search with sed to sort entries in a file
I have a text file of the following form:
dir1/sub-dir1/.../filename1 author date
dir1/sub-dir1/.../filename2 author date
.
.
.
dir2/sub-di2/.../filename1 author date
dir2/sub-dir2/.../filename2 ...
2
votes
2
answers
101
views
merge multiple rows in specific columns
I have a file like this:
xxx ax1 bx1
xxx ax2 bx2 cx2
xxx ax3 bx3
yyy ay1 cy1
zzz az1 cz1
zzz az1 bz2
...
I want the output like this:
xxx ax1,ax2,ax3 bx1,bx2,bx3 cx2
yyy ay1 ...