Questions tagged [sed]

Sed (Stream EDitor) is a command line editor for POSIX environment. Sed processes one or more files according to an editing script and writes the results to standard output. Created at Bell Labs, it has been around since the mid-70s.

1
vote
0answers
7 views

Using sed in Linux to extract lines from a log file

I have a log file which prints the following lines: 01:15:21.882 DEBUG [SampleProcess] Sample Message 01:15:21.882 DEBUG [SampleProcess1] Summary Report Sample Text1: 126 Sample Text2: 2330 Sample ...
1
vote
1answer
17 views

sed delete block of lines after pattern1 to pattern2, but not the line matching pattern1 itself?

I am struggling to use sed to work through 'testfile.txt' and every time it encounters a line that starts delete_me: abc it will then: leave the line delete_me: abc intact but delete all the lines ...
0
votes
1answer
10 views

Remove all path string from relative path

The following strings are in an html file that is a subset of the strings I have to work with: content/css/dashboard.css content/pages/icon-apache.png content/js/dashboard-commons.js sbadmin2-1.0.7/...
0
votes
3answers
22 views

How to code sed to delete multiple lines after a keyword until next blank line reached

Can anyone advise me on how to code a sed script that can be used to update a text file as follows: Each time a line in the file containing the character string 'Header_one' is encountered: - delete ...
0
votes
1answer
26 views

expand unix variable inside sed command

I need to replace current value in configuration file with new value which is assigned to variable , like file_name=abc.txt needs to be replaced like file_name=xyz.txt where $file=xyz.txt I ...
1
vote
4answers
33 views

regex to replace date part

I have a file like A_B_C_D_E_F_20180904_0038849_SUPER03.txt I want to extract just A_B_C_D_E_F.txt My try echo A_B_C_D_E_F_20180904_0038849_SUPER03.txt |sed -e 's/'_[0-9]{8}_.*'/'*.txt'/g'
0
votes
1answer
16 views

How to get the first number in a string using sed with 'sh'

I am trying to get the number of lines in a file. I am using: wc -l Example.master | sed 's/.\([0-9]+\)./\1/' This doesn't work for me, but I would have thought it should. It is not matching. In my ...
0
votes
1answer
30 views

sed with su misinterprets sed negation

This is simplified version of my actual problem. Here's my test.data file test.data ========= PROD SEARCH_URL = "google.com" db name "customers" TEST SEARCH_URL = "google.com" db name "emp" For all ...
0
votes
1answer
22 views

Not able to access tables from a corrupted MySQL Dump file

grep -n "Table Structure" dumpfile.sql returns XXXXXX:-- Table structure for table `table_name_1` XXXXXX:-- Table structure for table `table_name_2` XXXXXX:-- Table structure for table `...
0
votes
4answers
61 views

Find regex, move the next line at the end of this line and copy the first 5 columns to the next lines that start with a letter

I have such text: 37 7 -------------- No aaa 40 0 -------------- No bbb xxx zzy aa bb cc 42 2 -------------- No ccc xxx zyz a b c d 43 3 ---...
1
vote
1answer
31 views

why sed command fail with regex

I am using this command sed ':a ;{N;/\n/,/};ba' it is showing error in regex.kindly help to identify this problem. Full command SAMPLE_LIST=$ (ls*fastq.gz| awk -F"_" '{print $1}' | sort | uniq | ...
1
vote
1answer
16 views

sed match on one line and change another one

I want to go through a file (in this case it is apache2.conf), search for a line () that marks the beginning of a section and change another line (AllowOverride None to AllowOverride All) within that ...
0
votes
3answers
36 views

sed/awk/perl: find a regex, copy 5 columns of this line and paste to it at the beginning of the next lines

I have following lines: 057 - - No adod3 stptazlqn 10 753 tlm 10 027 stp 10 021 12 - - No azad1 bbcz 30 12 03085 ...
1
vote
2answers
32 views

Script to extract strings between two strings in linux

I am trying to write a little script that will let me "org-capture" articles from my rss-reader (newsboat). So my scenario is this: I will pipe the article to a script; however, the article gets piped ...
2
votes
3answers
29 views

bash SED command explanation with semicolon

What is this sed command doing? and is there any online utility that kind of explains sed a little bit, like regex? sed -i '1s/$/|,a Type,b Type,c Type/;/./!b;1!s/$/|,,,/' textflile.txt I think in ...
0
votes
0answers
24 views

Read the key/value from 1st Properties file and replace the value only in 2nd property file using sed (linux)

I have 2 properties file. Suppose "1.properties" and "2.properties" Contents of 1.properties is: file=abc.txt name=example location=xyz Contents of 2.properties is file=gh.txt name=example ...
0
votes
0answers
13 views

Which syntax for sed command with backslah?

I need to change this kind of content : "file":"\/home\/usr\/my-website.com\/data\/publication\/parameters\/21594\/1510849158.params" into : "file":"\/data\/publication\/parameters\/21594\/...
1
vote
1answer
20 views

Sed: replacing newlines with “-z”?

Problem: replace some regex with \n with sed. Solution: there are many similar answers [1][2][3][4], and many other links that I won't link. All of them suggest you to create a new label :a, merge ...
0
votes
0answers
28 views

How to replace the first and last character in multiple files in subfolder? [on hold]

How to replace the first and last character in multiple files in subfolders, using awk and/or sed
-2
votes
3answers
76 views

How to match two new lines (\n) instead of one, in regex? [duplicate]

I have a text file, Which is a dictionary containing over 80,000 words, I need to parse it someway or another, but first I need to sort it out, so I can parse it easily later. Is there a way in Regex ...
0
votes
1answer
16 views

Identation error on adding doc string to python code using sed

python code: def fun(a,b): c=a+b return c sed command to add doc string: sed -i '/^def/a \\t """\n\tSummary:\n\t-------\n\tParameters:\n\t----------\n\tReturn:\n\t------\n\t"""' filename ...
0
votes
3answers
28 views

replacement with sed does not work correctly

I tried following commands and explain my problem: $cat __sphlist__ signals/APASCI/algi0/algi0.sph signals/APASCI/ancl0.sph signals/APASCI/anpe0.sph signals/APASCI/cepe0.sph why the following ...
0
votes
4answers
48 views

unix extract data from file

I've got a file.sql file from an informix database export. The following is a small part of the file (I changed the data a little bit to make it anonymous): grant dba to "xxx"; grant dba to "yyy"; ...
1
vote
4answers
60 views

Search first pattern and search second pattern and then insert a new line above the second pattern

I got stuck with following text processing in a file, such that -> Search the first pattern and then search second pattern and then insert a new line above the second pattern. File Sample: some text ...
2
votes
2answers
42 views

Sed insert file contents rather than file name

I have two files and would like to insert the contents of one file into the other, replacing a specified line. File 1: abc def ghi jkl File 2: 123 The following code is what I have. file1=...
0
votes
4answers
61 views

changing Majuscule and minuscule cases

I have a file containing lines with one word in upper case and one other word in lower case like this : "BAMBARA"{ "bambara" } As output I want to have : case(BAMBARA) { template("bambara") }. So ...
0
votes
6answers
79 views

SOLVED: replace lines having only one field with space/char

I want to do two things in a long table, for which an example block is given below. (1) replace all lines having a single field (e.g. lines containing 102 and 103) with a character (e.g. the ...
-1
votes
2answers
47 views

Extract text between two markers and replace a character

I want to change >lcl|ORF183:9482:8118 unnamed protein product into >ORF183:9482-8118 Keep everything after | and before 'white space', plus replacing second : to - So far I'm doing it with ...
0
votes
2answers
49 views

Extract portions of two lines into one

I would like a command line that would convert this input: capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431) signal: -68.00 dBm last seen: 0 ms ago SSID: ENH202.FW ...
1
vote
2answers
34 views

Is it possible to tell sed to perform the subsequent subsitutions if the first one fails?

I can pass a variable to sed substitution command as following: $ myvar=helloworld $ sed -r "s/$myvar/hellofoo/g; s/foo/bar/g" <(echo helloworld foo) hellobar bar But if the variable is empty, it ...
1
vote
3answers
50 views

Unix - Replace column value inside while loop

I have comma separated (sometimes tab) text file as below: parameters.txt: STD,ORDER,ORDER_START.xml,/DML/SOL,Y STD,INSTALL_BASE,INSTALL_START.xml,/DML/IB,Y with below code I try to loop through ...
-1
votes
2answers
24 views

how to find a specific character combination and add a newline

I have a large file that looks like this (something,something1,something2),(something,something1,something2) how do I use sed and find ),( and replace it with );( or add a newline between the ...
0
votes
0answers
23 views

Removing non-printable characters with sed not working

I am working on AIX unix and trying to remove non-printable characters from file the data looks like in Arizona w/ fiancÃÂÃÂÃÂ in file when I view in Notepad++ using UTF-8 encoding. When I try to ...
0
votes
1answer
22 views

how to ignore special characters in a file while doing sed

I need to replace a string with contents of a json file. So my code goes like value=$(<minified.json) sed -i -e "s/<!--MyJson-->/$value/" file.html I need to replace the contents of json ...
-1
votes
1answer
28 views

shell script using sed to count number of lines skipping header and trailer records (n-2 lines of a file)

I am able to get the total no of lines in a file and was able to append the date|count record at the end of the file but the file has the header and the trailer record and I should get the count ...
0
votes
1answer
33 views

Sed and order patterns

I have a file that containes my target lines (start with '>') ... >lcl|1:c127-20 Ricardo3 phone I want to get : >Ricardo3:127-20 My steps: (1) Change ':' with ' ', (2) remove string 'c' and ...
2
votes
1answer
53 views

parsing lspci tree using regex

$ lspci -tv | grep -E 'Gigabit Network|Gigabit Ether| Ethernet' | grep -oP '(?<=^).*(?=Intel)' +-01.0-[01-04]----00.0-[02-04]--+-01.0-[03]--+-00.0 | ...
1
vote
1answer
47 views

Bash: echo showing blank value

I have two variables as follows SampleOutput=`some command giving output` Status=`echo "$SampleOutput" | grep -qs "Active"` echo $SampleOutput echo $Status Here $SampleOutput has value as ...
0
votes
0answers
30 views

remove non latin-1 characters in a text file [duplicate]

I have to replace all non latin-1 characters in the text of a large dataset file. An example is like LABEL chini vich 妈妈媽媽 maama LABEL 南支那海 南シナ海 shabadik ar h ngkhani shina saagar LABEL ॐ आप्या...
2
votes
1answer
46 views

Add blank spaces after substring while keeping the columns

I have a data file like this: randomthingsbefore $DATAROOT/randompathwithoutanypattern randomthingsafter randomthingsbefore $DATAROOT/randompathwithoutanypattern randomthingsafter $DATAROOT/...
1
vote
3answers
44 views

Bad substitution error when passing decremented variable to “sed” command

I like to use "sed" command to delete two consecutive lines from a file. I can delete single line using following syntax where variable "index" holds the line number: sed -i "${index}d" "$PWD$...
1
vote
1answer
44 views

Why does my Linux text file (created with echo) end with a newline? How can I remove it? [duplicate]

all experts I facing an issue with adding a new line with sed I want to add a line into the end of the text file, I tried with echo "Hello, how are you?" >> myfile.txt but the issue is its ...
2
votes
1answer
36 views

Replace the string either with sed or awk, where it identifies a patter as mentioned below

Could u please let know how can I convert the below INPUT into the mentioned OUTPUT using AWK: INPUT CREATE TABLE ${hf:XX_DB_XX}.test_${hf:XX_YYYYMMDD_XX} AS SELECT id FROM ${hf:XX_R_DB_XX}.usr_${...
-1
votes
6answers
53 views

How to replace a word in multiple lines using sed?

I am trying to edit a CSV file like this: 1:field1,field2,field3,FIELD I WANT TO REPLACE, fieldx ... 2:field1,field2,field3,FIELD I WANT TO REPLACE, fieldx ... 3:field1,field2,field3,FIELD I WANT TO ...
0
votes
1answer
24 views

if statement using “sed” to set variable not working

I'm trying to get an if statement to read the top line of a text file (tmp.txt) which has 0 on the last line. the "then" commands basically go into a directory and run a series of commands for DNA ...
0
votes
2answers
17 views

Match the same pattern n times on the same line using sed

I have an input file div.txt that looks like this: <div>a</div>b<div>c</div> <div>d</div> Now I want to pick all the div tags and the text between them using sed: ...
0
votes
2answers
14 views

Remove substring in file using sed command

Remove substring in a file using sed command in shell Eg. cat TR SAM9001,SAM9002,SAM9005 **Output:** 9001,9002,9005
0
votes
2answers
35 views

Replacing “// ” with “;” using sed

I am trying to replace in a file all ocurrences of "// " (without quotes) for ";". For example, this is file.txt: // this is a comment hello. And I want it to look like this: ;this is a comment ...
3
votes
1answer
52 views

How do you remove space from the beginning of a line using Plan 9's sed

Seems like this should just remove at most 2 spaces from the start of each line: cat test.txt | 9 sed 's/^ //g; instead it replaces all spaces from the start of the line. GNU's sed seems to be have ...
1
vote
1answer
50 views

How to use awk to select text from a file starting from a line number until a certain string

I have this file where I want to read it starting from a certain line number, until a string. I already used awk "NR>=$LINE && NR<=$((LINE + 121)) {print}" db_000022_model1.dlg to read ...