Stack Exchange Network

Stack Exchange network consists of 174 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 known as a Stream Editor in that it can carry out various filtering and/or transforming functions on standard input or on user specified files. It is commonly used to search-and-replace in text files. If your question is about text-processing, this tag is likely to be appropriate

0
votes
3answers
51 views

Extracting numbers from text files

I have some text files from which I want to extract certain data. I want to extract some specific numbers from them. In particular I want to search the files for the first occurrence of string1 and ...
0
votes
2answers
26 views

txt to pcap file conversion using sed and xxd

I have used this command to successfully convert a .txt file to a .pcap file. However these were all for .txt files I obtained from the www,but when i attempted to use it for .txt files I had ...
0
votes
1answer
21 views

How sed can be used to replace multiple patterns within a string for different patterns

I want to (1) replace multiple numbers in a line for different values. For example, in the string "uncertainty = { 0.01 , 0.01 }" it should substitute for string "uncertainty = { 0.2 , 0.2 }". The ...
4
votes
3answers
564 views

How can I remove enclosing brackets from a line?

Given a line like this: "hello my (name) is (user), how can I remove all '()' using sed? What I'm currently doing is highlighting the line using visual block, and then :s/(//g and again for ). Is ...
0
votes
1answer
35 views

Replace hex in binary file with shell without sed

I have binary file that I want to replace with shell script 0xaa,0xbb,0xcc,0xdd with 0x11,0x22,0x33,0x44 I can get 0xaa,0xbb,0xcc,0xdd into shell script like $1 but how can I replace it with 0x11,...
0
votes
1answer
22 views

Changing position of a character in a string

String: 34 /foo/bar_11,,, I want to insert "34" instead of the second comma. So my string should look like this: /foo/bar_11,34, How I can do it?
0
votes
1answer
75 views

How to replace consecutive characters from directory names, recursively

What is the best way to replace all consecutive characters such as _+-."'? from a directory and all sub directory's names using GNU bash, version 4.3, using tools awk, sed, Perl rename or find? AS ...
1
vote
2answers
75 views

Use sed to rename files in multiple directories?

I have a number of files in various directories e.g \images\00101191 \images\Books etc. I would like to rename these. I have exported their paths to a CSV file, which contains information in the ...
1
vote
1answer
45 views

Gnu sed, will the p command append a newline when printing?

I'm using GNU sed 4.5, per sed --version. I'm new to sed and I created below sed's workflow based on my understanding (correct me if you find anything wrong). So it seems the default auto printing ...
2
votes
2answers
46 views

Using SED to delete text in a file

I am trying to create a bash script that will manage a basic inventory system for a friend. Everything he wants to inventory has a barcode, that when scanned, returns a 6 digit number (EX. 000001). I ...
0
votes
1answer
37 views

Gnu sed regular expression extension, how to type these two characters?

This may be a stupid question, but I'm not sure and just want to confirm. Gnu sed has some regular expression extensions that work in both BRE and ERE mode. The following are an excerpt from the sed ...
2
votes
2answers
153 views

How to upgrade sed to 4.5 on Ubuntu Server 18.04?

I want to try the newest sed utility on Ubuntu Server 18.04. I've tried below command but still not able to upgrade it. How can I do that? root@u1804:~# apt update Hit:1 http://archive.ubuntu.com/...
2
votes
2answers
35 views

how to remove first N-1 lines up to a given input string

I'm trying to remove the first N-1 lines up to the first match of a specified string I am very new to scripting, but from my googling I believe I have the two commands I need, but don't know how to ...
3
votes
3answers
157 views

Replace String “Development” with “Staging” or “Production” using SED

I am trying to replace the string : 'development' with : 'production' using sed. I tried a few options including: sed -i "s|: \'development\'|: \'staging\'|g" index.php but without any luck. ...
1
vote
1answer
63 views

Find all files based on a list of file names / patterns [duplicate]

Say I have a list of keywords: $ cat filenames.txt satin perdido savoy stockings april lullabye I want to find all the files in some directory that contains those keywords. I have tried something ...
6
votes
2answers
90 views

Sed script crashing on big file

I have a shell script which is in essence a sed script with some checks. The goal of the script is to convert the header of a file from. &FCI NORB=280, NELEC=78, MS2=0, UHF=.FALSE., ORBSYM=1,1,1,...
0
votes
2answers
259 views

use sed to replace each white space with a backslash

just want to escape spaces in windows filepath. I'm trying this echo "111 1111 "| sed -e "s/[[:space:]]/\\ /g" that only match spaces but do not replace.
1
vote
3answers
82 views

How to add string at specific column in a file which is not a white space

How to add string at specific column in a file which is not a white space. cat file.txt abc defg xy Now I want to add string "test? at column # 8 of file.txt. But column #8 is not a white space ...
2
votes
1answer
39 views

how to create a regex string where you don't know what to escape

I have a passwd file with the line containing root being: root:6UZSjeWUui3JQ:0:0:root:/root:/bin/sh I want this line to be changed to: root:$1$dog$cNv/OuAd7CMNdrhWsHXAR.:0:0:root:/root:/bin/sh ...
3
votes
3answers
320 views

Edit text file to add space

I have a text file which looks like this ../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb ../pool/main/a/accountsservice/accountsservice_0.6.45-1ubuntu1_amd64.deb ../pool/main/a/accountsservice/...
1
vote
0answers
57 views

sed append multiple lines with special characters through bash file

Ive been trying to figure this out for a awhile now but need to phone the experts. sed '/#algoscreens/ a\ '${coinname}'="screen -dmS '${coinname}' bash $STRATUM_DIR/run.sh '${coinsymbol}.${coinalgo....
0
votes
1answer
23 views

Extract only package name without version using awk or sed

cat pkg.temp ca-certificates-2017.2.14-65.0.1.el6_9.noarch glusterfs-3.7.9-12.el6.x86_64 glusterfs-api-3.7.9-12.el6.x86_64 glusterfs-api-devel-3.7.9-12.el6.x86_64 glusterfs-client-xlators-3.7.9-12.el6....
1
vote
2answers
80 views

sed add line (without spaces at the beginning ) after match (script using variables )

Please help with spaces when script add line after searched pattern $ cat test.txt test server:1 prod server 1 $ cat ./check.sh #!/bin/bash # search=" test server:1" add=" ...
0
votes
1answer
47 views

sed new lines with \n as part of the line text

trying to write a new sed command that will insert new lines before another line. the code i have tried and is failing is: sudo sed -i '/# onlynet=ipv4/i echo "rpcallowip='$WebInternalIP'\n";\necho ...
1
vote
3answers
121 views

sed: -e expression #1, char 10: extra characters after command

I would like to take the first 2 lines from test.txt: hello my name is and put them at the top of a new file, output.txt: foo bar with the desired output being, output.txt: hello my foo bar ...
2
votes
1answer
18 views

Delete string and associated newline [duplicate]

I'm trying to edit a file on a remote server via a terminal and to make a change in said file I have to (or have used so far) use the 'sed' command. in the below file i want to delete the string ...
1
vote
1answer
61 views

How can I replace [0] with ascending numbers in a text file?

I want to change a file with text like this Application[0]=test_app1 Application[0]=test_aap2 Application[0]=test_app3 Application[0]=test_app4 .. to have ascending numbers like this: Application[0]...
0
votes
1answer
66 views

strange behavior with sed and text files on Ubuntu

Ok first of all, i'm working in a VPS with Ubuntu 14.04.5 LTS I'm trying to manipulate several text files with sed and my results aren't what it was suppose to be and i can't find a reason for that.. ...
0
votes
1answer
62 views

how can sed match pattern delete line plus one and insert diferent file

I believe i'm pretty close but there is 1 command missing.. i have file1.txt rrrrrrrrrrrrrrrrr dddddddddddddddddd id="8" efwef aaaaaaaaaaaaaaaaaaa cccccccccccccccccccc xxxxxxxxxxxxxxxxxxxxx file2....
2
votes
0answers
90 views

Converting a string of Perl code to BASH code

I have this string of Perl code (which i didn't write) that it would be awesome if is converted to BASH code: perl -pe '$j=0; while ( s{.{$j}\K(\d+):}{/} ) {$j += $1+1}' By using it in terminal: ...
-1
votes
2answers
79 views

grep and sed only the numbers from a text file's line

I'd like to extract only a number from a text file. It is like: corner_lat: 49.0425000 decimal degrees I am using the following expression : grep corner_lat EQA.dem_par | sed "s,[^0-9]*,," ...
0
votes
0answers
28 views

How to recursively go through all text files in a directory to fetch the desired line, and write these lines to same text file?

I have a directory which has text files (HTML pages). I wish to use SED to go through these text files, find the specific line, and write the line to a single text file. So for example I have HTMLS ...
1
vote
1answer
40 views

I need to insert a large string in between two pattern using shell script

I have an HTML file in that I have a comment line as: <!-- tag1 --><!-- tag11 --> I need to insert a JQ file element in between them. I have tried and I was able to insert a small ...
3
votes
1answer
135 views

Delete ranges of lines, but skip the comments which come in between the lines

I have a file with the following contents: Windows user I love windows Windows 10 # I like it # I want to keep these two lines Just started with my job New to shell scripting as well New to Mac ...
0
votes
1answer
148 views

Python syntax error with awk, sprintf statment (2.7)

I am trying to use one of the shell commands to a python script, but struggling with some syntax error here. The description of the command is from here echo /dev/bus/usb/`udevadm info --name=/dev/...
9
votes
2answers
783 views

Using AWK to get second column

I can not seem to get the awk command to get the second column of data. Bash Code: filter_data=$(awk "{if(/$filter:/) print $2}" < scanresults_temp.txt) printf "$filter_data \n" The $filter ...
0
votes
1answer
25 views

how can i extract my ipv4 mac address with tcpdump and sed

I recently changed my mac address and also whenever doing so, i want to make sure it changed on the network, not only on nmcli or ifconfig I'm running sudo tcpdump -i enp2s0 -en to find my MAC ...
0
votes
1answer
95 views

How to change a hypen to a period in a file and/or directory

I'm trying to do this in linux/bash. I have multiple directories. I don't mind doing each one individually as there are just a few. In each directory, there are files and folders with names like... ...
-1
votes
2answers
290 views

Insert a line of text after the line containing the last occurence of a specified word

Basically, I want to insert a line of text after the line containing the last occurence of a specific string, without affecting the rest of the file. I imagine I should proceed like this: delete ...
0
votes
4answers
57 views

How to count the characters within quotes?

Example: Known Data: Total population = "150" Question: Using bash how can I find out the number of characters within quotes? and assign that output to a variable?
1
vote
1answer
86 views

Cutting a string using sed

There is a string, which contains numbers and letters in its name. The symbol '_' divides different parts of the string. X23X_1XY4_XXXX_Y12Y_YYX2_XXYY I want to have only second, third and forth ...
0
votes
1answer
30 views

Wrong sed with regexp

I have log file. I want extract email list from specific lines. Sample log file: 05:06:48,311 INFO http-nio-8080-exec-81 controller.IndexController:221 - Attempt to login: [xxx@yyy.com]. Headers: ["...
0
votes
2answers
84 views

Escaping a literal string for sed

How can escape the literal string #!/bin/bash in a sed expression? Curently I have a command in a bash script of the form sed 's/Parametersettings:/HERE/g' outpad1 > outpad2 I would like the ...
1
vote
1answer
395 views

In a bash script how do I pass a variable integer to a 'sed -e' command (18.04)

I'm trying to create a bash script that trashes the oldest files in a directory with a variable setting the amount of files to retain. My first step was to count the number of files older than a set ...
0
votes
1answer
26 views

how can i use sed to remove a ] special character

how can i use sed in a special way to remove apart of a special character sed s/^}$//g > file doesn't do anything, I'm trying to remove the beginning of every line up to the bracket, so that ...
0
votes
2answers
392 views

sed: unknown option to `s'

I am trying to use a shell script file in the Bash shell. In this script, 2 sed commands are there. The second sed command is following. sed -e s:MACRO_NAME:"${runmacro}":g \ -e s:...
3
votes
3answers
187 views

Delete all lines from middle of a line matching a string until the second string match is found

I am trying to remove the error messages printed into my file. I have this: addr:1122c:1234: addr:11230:5678: addr:11223:01Error:abcdef(x, y) = z, value = a Error:hijklm(v, q) = w, value = b Error:...
2
votes
1answer
183 views

How to replace a xml file line using sed

I have the following text in File.XML: <http-listener name="default" socket-binding="http" max-post-size="1073741824" /> I would like to replace that with <!-- <http-listener name="...
1
vote
2answers
58 views

Can I non-manually add a comma to the end of hundreds of lines of text?

I have hundreds of rows of text like so: aaabbbccc dddeeefff ggghhhiii They do not have a space at the end. I want to add a comma to the end of each line. Is there a way to non-manually achieve ...
0
votes
1answer
30 views

How to get sed to work for parametric expansions?

The current script is for r in $path/[0-9]*.tst; do sed -i s/val1/${r%.tst}/ $path/foo.bar sed -i s/val2/${var2}/ $path/foo.bar sed -i s/val3/${var3}/ $path/foo.bar sed -i s/val4/${var4}/ $path/foo....