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

Filter by
Sorted by
Tagged with
0
votes
2answers
37 views

How to append text in the beginning of each line using sed

<AppendNhere> A H W C <AppendNhere> A H W C <AppendNhere> A H W C Sed '/^/ i N' filename I tried appending N using this, but it's appending N to the beginning of new ...
0
votes
3answers
43 views

Removing characters (digits) after the first dash (-) from the end of a fileName

I have thousands of .mp3 files that have recently been required and were appended with a dash - and a series of various amounts of numbers. I would like to remove the last dash and the numbers to ...
1
vote
1answer
32 views

Find index.html files & Rename with folder name and move file a level up

Little help in solving a workflow with shell script using the find command. Finding all index.html files in every folder. We can use this with find command for that. find ./ -type f -name 'index....
0
votes
1answer
22 views

Change regex's result order after sed as order of ls -v

I am working on 53 xml files (az-0.xml ~ az-52.xml). And I ransed '/<loc>/!d; s/[[:space:]]*<loc>\(.*\)<\/loc>/\1/' az-*.xml > AZ to get all stuff in <loc> and merge them ...
0
votes
0answers
33 views

Using sed to find a word and replace another word

I have a word like <string>any word</string> in a file. I want to replace it with <string>17E262</string> For example: I want to convert <string>16G183</string>...
2
votes
2answers
63 views

Remove word and character from strings

Is there a method to remove this string "name": "_acme-challenge", and left only with : _acme-challenge I read that I can use sed but I don't understand much how to go with this.
1
vote
1answer
123 views

Filtering the lines which are greater than a percentage value

Hello i need to filter lines which are greater and equal than 85%. I need to filter according to Forward: Score line and end of the percentage of that line. Example file: Scores for this hit: >...
2
votes
2answers
169 views

How to delete the string pattern from a file between 2 colon character

Searched a lot lot but didn't find any solution. for example: if string is a12345:hello world:hello world again:other string output: a12345::hello world again:other string so I just wanted to ...
0
votes
0answers
39 views

Trying to replace header

I am trying in my code base to replace existing license headers with a new license header via bash. I stored the new header in the same place as my bash script named licenseHeader.txt. It only ...
0
votes
2answers
32 views

replacing the particular line in bash

I wanted to change 800 line in one file say test.txt if i use the below command it works sed -i '800s/old_pattern/new_pattern/' $filepath Is there a way to pass the line number through variable ...
2
votes
2answers
51 views

Deleting a line and lines after it

I'm trying editing some text file using sed. In the text file there are two lines starting with a string. I want to delete only the first one and say 3 lines after it. How can I do that with sed? ...
0
votes
1answer
21 views

sed - replacement group in command line double quoted

I am trying to run this sed -i -e "s/'(\${RConstants\.staticPath}\/dist\/img\/app\/icons\.svg#[a-z_-]*)'/`\1`/g" test Single quote version sed -i -e 's/'\''(\${RConstants\.staticPath}\/dist\/img\/...
0
votes
2answers
138 views

bash - Unexcepted Token

I'm writing a bash script to automatize my downloading process. In a section, it gaves a error: syntax error near unexpected token `newURL=$(echo $URL | sed 's/&:/$index/')' That section of ...
1
vote
2answers
64 views

Shell script to switch first and last names and sort records

I am newbie and I am stuck on this problem. I need to switch the first name and last name. There are no spaces between the first name and last name just a comma. I need to change this: firstName,...
0
votes
1answer
28 views

How to control gzip and sed process

I use Ubuntu Studio 19.10, Linux 5.3.0-40-lowlatency (x86_64). Since a while, one of my PCs, is working a lot with some process (apps) I've never programmed to work: "GZIP" and "SED" (and there are ...
0
votes
2answers
133 views

grep / sed / awk / count between two lines in file not whole file

I have this file on my laptop /etc/dbus-1/system.d/org.freedesktop.thermald.conf: <?xml version="1.0"?> <!--*-nxml-*--> <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus ...
0
votes
0answers
72 views

how remove null and ctrl+m characters from csv file linux

i have csv file that start with NULL bytes that come from hive beeline cli query output , the file start with many lines that have ^Mnull^Mnull in the first lines . i tried tr -d '\0' < ...
1
vote
1answer
100 views

using sed to find, compare and replace text

I have a text in a single file Quiz Worker(Thomas) works in .......... Worker(Alfred) works in .......... Worker(Albert) works in .......... Answer Worker(Thomas) works for company(google) ...
0
votes
1answer
45 views

sed script for modifying the start and end of a para in even/odd fashion

I wish to use sed to modify the starting and ending pattern of a code with odd/even occurrences in block/para, for e.g. Word1 ..... Word1 Word1 ..... Word1 with replacing "word1" in the beginning ...
-1
votes
1answer
53 views

Sed, extract lines from text

I really would like to know how can I extrac some line from a text file using sed, but I'd like to extract the lines at interval: For example extract the line with number i=1:2:100 So that i can ...
2
votes
2answers
81 views

Usage of sed(stream editor)

I have a file containing text **This is bold text** *This is italicized text* I wish to convert the above into \textbf{This is bold text} \emph{This is italicized text} using stream editor(...
-1
votes
2answers
61 views

using sed to convert camelCase to under_score

I have a sed script that can convert camelCase to under_score which works great for this example: myvar="camelCase" converted="$(echo $myvar | sed 's/\([A-Z]\)/_\L\1/g;s/^_//')" echo converted // ...
1
vote
1answer
110 views

how to trim few words in 2nd column to display in a text file

Original: 'abc','X:1234','cde', 'YYY', 'XYZ' 'abc','X:2345'','cde', 'YYY', 'XYZ' Want to outcome with the below, in which 2nd column trim to 4 characters, before is 6 charaters. 'abc','X:12','cde',...
-1
votes
1answer
63 views

Replace XML tags by numbers

Suppose i have an xml like this <a> hey how are </a> <a> where are you </a> I want to change them and assign number like this-- 1.hey how are 2.where ...
0
votes
1answer
41 views

Remove double slashes from several strings with sed (current idea not working)

I am trying to replace the double backslashes (//) from the items below: //listen-on port 53 { 127.0.0.1; }; //listen-on-v6 port 53 { ::1; }; //recursion yes; (I don't know if it's important to ...
3
votes
2answers
170 views

How to insert filename by changing format to same file?

I have many files. File format is year(4-digit)month(2-digit)day(2-digit) Sample filenames: 20150101.txt 20150102.txt Content of sample filenames 00:00:13 -> 001528 I want to extract data as ...
7
votes
4answers
572 views

How would you separate fields with multiple spaces and store them in an array?

In my file mytxt: field1 field2 ------ ------- this are numbers 12345 this letters abc def ghi Let's say I want to store the first field ...
1
vote
1answer
51 views

Manipulating a continuously changing command output stream

I'm trying to change the output position of a file transfer made with rsync, as shown below: rsync -zvh --progress ubuntu-19.10-desktop-amd64.iso /home/lnxusr/Downloads/ From this: ubuntu-19.10-...
0
votes
1answer
178 views

sed: -e expression #1, char 5: unterminated `s' command

I get his error when using sed: sed 's/H/q' myout00 sed: -e expression #1, char 5: unterminated `s' command cat myout00: Fname Lname Net Algo OS NSec Sof Sadegh SamanI 15 20 14 19 ...
1
vote
1answer
137 views

How can I change the third occurrence of a word in a file using sed?

I need to change the 3rd occurrence of 'None' in a file text.txt using the sed command. I found this command sed 's/None/All/3' text.txt but this works for 3rd occurrence of 'None' in a line, not in ...
2
votes
1answer
747 views

'sed' not replacing text in file

I am attempting to replace tokens in a JSON file with values held in our CI tool of choice (Bamboo). To do this, I am using jq to extract an array of values, and then replacing the token in each ...
-2
votes
1answer
48 views

Copy files such that individual files gets copied to the folder having file name as a string within complete folder name [closed]

I am using Cygwin as Linux shell, I have following contents in my current working directory: Files : Abc.dat 123.dat 456.dat Directories: W_Abc_w W_123_w W_456_w Now I want to copy files as ...
0
votes
1answer
1k views

Add or append new column to csv file using shell script

I have a CSV file it includes some columns, in that I have the start time and end time. My requirement is to get the difference between the time and add the difference to a new column. I'm getting ...
2
votes
2answers
344 views

Bash: trying to make a “sed-replace”-function, robust to arbitrary character input (expansion, substitution etc)

I'm trying to make a "sed-replace"-function with arbitrary input as argument, but it doesn't work well. Let me illustrate the problem, first by showing the input file (a simplified file): $ cat /tmp/...
1
vote
1answer
141 views

Remove lines starting with “string1” and NOT containing “string2” with sed

I would like to delete some lines in a file with more than 100K lines of data. I only want to delete line which started with MX and NOT containing the word sum. How can I do that with sed? ...
0
votes
2answers
105 views

How to convert gjf format to xyz format?

The gjf format is as follows: %chk=test.chk # hf/3-21g geom=connectivity Title Card Required 0 1 C 0.53424883 1.46721985 -0.02620215 H 0.89090326 0....
1
vote
3answers
174 views

how to grep two paragraph from file?

i have file "test_file.txt". My output must contains all"IP ADDRESS" and "MONTHS OF 2017" from file test_file.txt. Server$ Server$cat test_file.txt IP ADDRESS: 1. 172.17.17.17 2. 172.17.17.18 3. ...
2
votes
1answer
46 views

Using sed with a custom function fails

I'm having a huge csv file that is url encoded. I would like to decode all lines, and I thought sed could do the trick for me, but I can't make it work. Here's my script: #!/bin/bash function ...
0
votes
1answer
31 views

grep a word/number between two specific characters

When you ping you will get the ip between () , for e.g : (10.10.10.10) and after the ip there are (number) for e.g : (10.10.10.10) 56(84) so how i can get the ip that is between the () ? and without ...
0
votes
1answer
41 views

Problem using sed with files containing quotation marks

Using sed 's/$/x/' and entering the string foo"bar to standard input gives the expected result foo"barx However, putting the same string into a file and running sed 's/$/x/' filename ...
0
votes
1answer
48 views

Accidentally removed kernel and basic drivers (internet touchpad graphics not working)

I had been having low storage issues on my root partition so I tried out some cleaning advice from this forum, including (Root drive is running out of disk space. How can I free up space?) and also (...
1
vote
3answers
103 views

How do I remove lines with sed that contain more than 1 word?

I need to remove lines from a file that contain > 1 word. Here is an example of the file's content: This line is not what I need printed-now. would print This not printed-now. I have tried: sed -...
0
votes
1answer
51 views

I need to pull email size for each email in a sendmail log, then total them up with the total size and total number of emails

The size is simple to find after size= i can find the size and put it to a file but removing everything but the numbers and then summing it with the total numbers all in one file is just not coming ...
0
votes
0answers
45 views

extract specific strings from a file [duplicate]

Using cat index.html | grep 'src.*js' I got these results: <script src="/c/dam/cdc/j/adrum.js"></script> <script type="text/javascript" src="/c/dam/cdc/j/targeter-bundle_min.js"><...
7
votes
1answer
292 views

How can organize the disordered columns using awk/sed?

I have 2 columns including some data like: one two one two one two How can we convert it to: one two one two one two
0
votes
1answer
215 views

update hosts file on boot

I'm trying to fix a problem where sudo takes a few seconds if the hostname is not in /etc/hosts. this works from CLI: sed -i "s/ubuntu-template/$HOSTNAME/g" /etc/hosts but if I save it to a file /...
0
votes
1answer
35 views

replace 64 different OLD strings with 64 different new strings

I have a file that has content in the following format: wwid 525a9370dcb2348b03884049000190l The 2nd field is different on each line I need to replace 64 of these lines with 64 new different ...
0
votes
0answers
13 views

sed, get only strings in links from html, some are missing

Issue I have html file and with sed I would like to get all links from document, with page number, as csv. All is ok, but when are for example 2 <a hrefs on one line, it takes only 1, others are ...
2
votes
1answer
1k views

Using grep and sed to make changes to a config.yaml file

I have a config.yaml file which i want to edit or make changes to using a bash script. So i got a command using grep and sed which gives me the desired changes , but the problem is that when i apply ...
3
votes
1answer
94 views

Add specific text/tag after every few lines in bash

I have a text file where I have to add tags (in the form of normal text) to a .txt file. For example, suppose I have a text file like this: a b c d e f g h I want to add the tags <hello> and &...

1
2 3 4 5
12