Questions tagged [sed]
"sed" ("stream editor") is a Unix utility that parses and transforms text files.
1,041
questions
0
votes
0
answers
190
views
When piping sed command, output becomes all spaces
This is for a lab I have in a class, the professor has told me to use sed to remove all punctuation and double spacing by piping together several sed commands. When I pipe the commands together my ...
0
votes
1
answer
34
views
cannot replace specific characters in stream edit
sed is such a wonderful tool, but for some reason I cannot make it do what I need this time.
I'm working with huge datasets in csv.
Some files are delimited with ;(semi colon) and others with ,(comma)
...
0
votes
1
answer
894
views
how to use sed to substitute a string with another string starting with $?
I want to replace the content of a file
cat test.sh
attribute = "metaapp"
so I am trying to replace the metaapp with string ${meta.app} with hep of sed using
sed -i s/metaapp/${meta.app}/g ...
1
vote
2
answers
803
views
sed read multiple lines for a regex replacement
I need to get this PCRE regular expression working on sed:
(\)\;\s)(INSERT INTO )\`(.*)\` VALUES \(
Working example available here
Thanks,
3
votes
1
answer
1k
views
sed Error sed: -e expression #1, char 7: unterminated `s' command
I keep switching between my command prompt and my git bash shell on windows 10. Suppose I copied my current directory to the clipboard in my command prompt(cmd.exe) and want to switch to that ...
0
votes
2
answers
2k
views
Replace random string using sed
How do I replace random strings using sed. For example if I have a text file like this:
EF125353.1 to be replaced 1
EF125353.1 to be replaced again 2
EF125353.1 to be replaced etc etc 3
And I would ...
0
votes
2
answers
2k
views
replace long text with special characters with sed
I am using sed in unix to replace some text with special characters in a file. I google it and find the following command
sed 's/from/to/g' file.txt
here 'from' is the original text being replaced, '...
1
vote
1
answer
188
views
Search and Replace words using SED utility
I have more than hundreds files (file1.txt ,file2.txt.....filen.txt) with below contents in Unix box.
file1.txt
location: $test/$type/path1/abc/testtable_123/
table: $database.testtable_123
file2.txt
...
1
vote
1
answer
583
views
AWK/SED/GREP - print M lines after the Nth occurrence of a match
I am looking to display M lines after the Nth occurrence of a match. Actually I need to do this in order to split a file containing Nth <regex> always followed by M lines into Nth different ...
-1
votes
2
answers
14
views
How to remove 3 last numbers, seperated by space, in each line of a file - and remove everything exept said three numbers
I need to split a file containing data of this type;
Jazz Guitar 1 16 3 4
Carlos Guitar1 16 3 5
Overdrive Gtr1 16 3 6
Western Gtr&Whis 16 3 7
Pat Guitar Synth 16 3 8
Shadow Guitar 16 3 9
Clean El....
31
votes
18
answers
84k
views
List only the device names of all available network interfaces
I want to get a list of all available Network-Device Names on my Linux server. I figured that
ifconfig
would do the job, however ifconfig produces quite much output:
eth0 Link encap:Ethernet ...
0
votes
2
answers
1k
views
How to find and replace in linux on a large file?
Oh, hi;
So I've got this big json file and I'm trying to find and replace a few things but when I've used sed I get an error and I need a sed or awk string to find and replace it, without getting an ...
1
vote
0
answers
363
views
sed: regex input buffer length larger than INT_MAX [duplicate]
i am trying to sed and change something from a json file and i am getting this error.
prajwal
sed -i 's/{"telephone_numbers":\["1-/{"telephone_numbers":["+1-/g' output....
2
votes
2
answers
629
views
Combine strings with same first word preserving their order
I have a file that contain many lines consecutive and non consecutive with same first word and i want to merge all those lines.Not finding any way. please suggest someone.
eg.
cat file
X blah blah ...
0
votes
1
answer
256
views
How to avoid creating an empty file with gsed?
Most of the sed-invocations redirect its output into the desired file. Which means, the file is created (by the invoking shell) even before sed is actually invoked...
Which, in turn, means, if sed had ...
2
votes
1
answer
2k
views
Remove all characters after first non-numeric character using sed or awk
TL;DR:
How can I create an expression using either sed or awk that will remove all characters after (and including) the first character that is not either numeric (i.e. [0-9]) or a period (.). I've ...
0
votes
2
answers
376
views
How can I change the end of a line depending on what is in next line?
I have a file full of text like:
CREATE TABLE `wild_adventure_game` (
`game_instance_id` bigint(20) unsigned NOT NULL,
`free_game_config_id` bigint(20) unsigned DEFAULT NULL,
`respin_instance_id`...
0
votes
1
answer
2k
views
Use sed to replace $ in a tcl script
I have a file which contains following:
@$test123
@$test456
$test789
In tcl shell, I want to replace ^$,
I tried following but it doesnt seem to work:
eval exec grep test file | sed s/^\$//
@$test123
...
1
vote
1
answer
54
views
Replacement of text between two matches, from one file to the other
So I have two files:
/etc/some/file1.xml
/etc/some/file1.xml_bck
These files are config files with bunch of directives in it (all in one line).
Content looks like this:
<SOMETHING>somehost....
0
votes
2
answers
51
views
delete a certain character/characters from files recurrsively in ubuntu
I have 8000 odd files and I need to cleanse them. I am currently using this sed command to replace certain characters with the ones I want:
find . -name "*.txt" -print | xargs sed -i 's/a/z/...
1
vote
2
answers
77
views
pattern match special charecters and display contents between the pattern
My apache log format is as below
192.168.10.1 <"www.mytest.com"> <-"-"-> <--“192.168.10.90"--> [2020-07-10 03:35:46 PDT] >1008< 2470 3006 "https&...
1
vote
3
answers
278
views
Extract filename ending with tar.gz from a URL where URL and filename changes frequently
Looking to extract the filename ending in tar.gz from a URL, where the URL, location and filename might frequently change.
https://s3.eu-central-1.wasabisys.com/testing/snapshot-latest.tar.gz
https://...
1
vote
2
answers
1k
views
How to remove all spaces at the end of strings in a text file in linux
I have file named a.txt and it contains strings but got some additional spaces at the end
cat -vet a.txt displays
ab cd^M$
abcdefg ^M$ //there is a space at the end
aaaaaaa^M$
bbbbbbb^I^M$ //there ...
0
votes
2
answers
463
views
How to change third column of a variable so it is encased with single quotation marks using AWK or SED
I have a variable $out:
out=1,2,3,4,5
I want to change the third column so the value gets single quotation marks as in (I talk of columns here as $out represents the values of an insert statement for ...
65
votes
7
answers
66k
views
Newlines in sed on Mac OS X
I find that \n doesn't work in sed under Mac OS X.
Specifically, say I want to break the words separated by a single space into lines:
# input
foo bar
I use,
echo "foo bar" | sed 's/ /\n/'
But the ...
0
votes
3
answers
1k
views
sed + how to replace numbers with parenthesis with sed/awk/other
we want to relapse the [1023,1024,1022] as described in the following file , with [1022]
more file.exm
{"topic":"nj_hgf_dfgef","partition":0,"replicas":[1023,1024,1022]},
{"topic":"nj_hgf_dfgef","...
0
votes
0
answers
458
views
Sed: Perform pattern search in reverse order in a certain range and get the line number on each match
I want to search the pattern in a certain range but in reverse order. For example if I give the range say 200,250 then I want that search should be performed in reverse order means search should start ...
2
votes
1
answer
8k
views
How to exit `sed` after the first match?
I need to search a pattern I/f in a file between some range of lines and quit on the first match. For that I am using sed command like this
sed -n '14922,28875{\|I/f|=}' file.txt
It actually prints ...
1
vote
2
answers
2k
views
Insert output of curl command to a line number in a file
Working on a script to automate a few things. Been having and issue with running a sed command to inser the output of curl to a line number in a file
I have tried multiple variations of the command ...
5
votes
4
answers
16k
views
Rename CSV header using command line tools
Given a CSV file,
h1 h2 h3
a b c
z x b
how to rename the first header to One and the third header to Three using command line tools, namely
One h2 Three
a b c
z x b
2
votes
1
answer
216
views
regex - replace ordered list of lines matching a string with another list
I have such confused ideas I couldn't describe well the problem synthetically, hence the title is horrible. Suggest me a better one too, while you're at it.
Basically, I have two SubRip (.srt) ...
0
votes
1
answer
900
views
Trying to use Sed with regex to fetch data from a log file
Hello I am experience difficulty to extract data from log file with sed -E command.I see regex is different than this I use in python.
INFO [2020-05-10 17:37:34] [armada.gloge] Username [109/15654]
...
2
votes
1
answer
2k
views
Pipe the output of “ls -G1” to “sed” while retaining output colors in macOS
When using the terminal in macOS I created an alias in ~/.bash_profile that lets me list folders and files in one column and with color using the -G1 option like this:
something = "ls -G1"
This work ...
0
votes
2
answers
31
views
Replacing a number ended in dot at the beginning of the line with '.IP number\n'
I want to replace numbers followed by period at the beginning of the line:
1. The quick brown fox jumps over the lazy dog
12. The slow grey cat jumps over the lazy dog
234. The strong yellow lion ...
2
votes
1
answer
670
views
Sed a file to include `pwd`
I'm not able to figure this one out. In a file called docker-compose.yaml I want to substitute ROSPERSISTENT-PATH with the result of pwd + "/rospersistent" which seems like a job for sed. But I am ...
0
votes
2
answers
3k
views
Replacing a string inside of multiple text files
I am looking for a way to replace line 5 and line 7 in many documents inside of a directory. Line 5's offset and line 7's value are different for each of these documents, however, I need them to ...
2
votes
1
answer
5k
views
Use a variable that could contain special characters into sed?
I have a bash script that'll take any word passed to it as a parameter and then encrypt the word using an openssl command. From there I want to take the returned string and use sed to write it into ...
1
vote
0
answers
31
views
Modifying a PBN file with sed [closed]
(Complete beginner in sed.)
In sed, how do I do the following?
In the below-example .PBN (Portable Bridge Notation) file:
[Deal "N:Q5.KT653.AJ.KT52 73.AQJ984.9543.8 AK9.7.Q876.AJ943 JT8642.2.KT2....
1
vote
1
answer
988
views
Read a file and replace dot with colon using sed command
Im trying to read and substitute period(.) with colon (:) from the below input file using sed regex expression.
Can one please check and suggest me.
Input File has 12.23.45
Expected is 12:34:78
...
0
votes
1
answer
2k
views
Best way to store multiple values from a running process into variables in bash
The problem
Starting a process will output sensitive information on the bash. I want to extract this value of an occuring pattern and assign it to bash variables. In concrete, starting the process ...
0
votes
1
answer
112
views
Removing lines from files with a specific extension
The task is as follows: From all *.h and *.cpp files, delete lines beginning with /.
Removing from the current directory (or from the specified one) works well, and if there is a subdirectory in the ...
1
vote
2
answers
1k
views
how to extract a specific part of a string from character 7 to 17 and save it in new txt file (findstr, gnu32-sed or other tool)
How do I extract a specific part of a string from character 7 - 17 using regex via the command line?
My string is ThisString and in the file data I have a lot of strings, but I need only ThisString ...
0
votes
1
answer
365
views
How to substitute every opening curly brace that changes bracket balance from 0 to 1 with sed/awk?
Example input:
void C::foo()
{ // <- this changes bracket balance from 0 to 1
if (true)
{ // balance is 2 after we process this bracket
...
} // now it is 1 again
} // now ...
0
votes
1
answer
3k
views
sed - replacing string with variable containing?
Please help, I am not getting anywhere despite extensive search in here.
I have a html file, and I want to replace some of the links it it - problem is, some of the links have a ? in it.
original='...
1
vote
1
answer
100
views
change line starting with# with sed -i
I want to uncomment a line in /etc/apt/sources.list to enable canonical repo but it seems it has a problem with # character I tried -e but I can't figure out if I'm doing it correctly
sed -i ' s/# ...
1
vote
2
answers
1k
views
Comment xml segment using shell script / command
I am trying to do a shell script with 2 parameters.
xmlcomment -c cholo
or
xmlcomment -u cholo
Given the following xml file,
<?xml version="1.0"?>
<guyList>
<guy>
<name&...
9
votes
2
answers
13k
views
How greedy is sed in matching patterns?
I know sed is greedy when matching patterns. But, how greedy is it?
Consider these examples.
$ echo 'foobar123' | sed 's/[0-9]*/(&)/'
()foobar123
$ echo 'foobar123' | sed 's/[0-9][0-9]*/(&)/'...
0
votes
1
answer
2k
views
Remove Strings from files using sed and grep
we are trying to remove a single line of injection code in thousand files of our server of these thing using grep and sed:
<script type='text/javascript' src='https://dest.collectfasttracks.com/y....
0
votes
1
answer
504
views
Use different sed replacement on one matched sed group
I'm an experienced software developer, but just now going back and gaining sed skills.
I have a file text.txt that contains lines in the form:
blah blah blah
key-1:foo-bar
key-2:foo-baz
more blah ...
0
votes
1
answer
161
views
SED failing, why?
Also see: String manipulation - get part after a certain word
My script:
# get list of curent possible F2B 'get' options, as a array (omitting the 'action..') ..
f2b_opts_cmd="$(sudo ...