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 a command-line stream editor for filtering and transforming text.

2
votes
1answer
26 views

Replace text using sed and also add single quote to it

I answered this question, but I am stuck on the part where I have to add a single quote also to it. Like original file is: $$BATCHCTRL=TEST-012017 $$STATE=CA AZ $$FROM_DATE=01/10/2017 $$TO_DATE=01/...
1
vote
1answer
22 views

collect logs from bash each 24 hours [on hold]

my idea is to collect logs each 24 hours ,mail it and flush them after that i wrote some scatch for example 1.var/log/auth {some info} 2.var/log/something.log {some info} list="$(find /var/log -...
3
votes
4answers
57 views

Why does `… | sed 's/^/stdout: /'` print on empty stdin when `… > >(sed 's/^/stdout: /')` doesn't?

I'm trying to understand what causes the difference in these 2 constructs that I thought were functionally equivalent: $ ( echo foo >&2 ) 2> >(sed 's/^/stderr: /') | sed 's/^/stdout: /' ...
0
votes
1answer
40 views

How to print one line below the matching RegEx in AWK or SED

I have a file containing several switches and the boot variables. lax1-sw0101#show boot --------------------------- Switch 1 --------------------------- Current Boot Variables: BOOT variable does ...
-1
votes
1answer
22 views

how to capture details from nc

by the following command we can identify which ip are using port 2181 and the relevant port echo stat | nc localhost 2181 Zookeeper version: 3.4.6-91--1, built on 01/04/2018 10:34 GMT Clients: /182....
0
votes
2answers
48 views

Extract and rearrange from file

I have file which I want to extract and rearrange certain data , Old file contains a raw data this file is Input reference:cve,2017-8962 sid:45885 reference:cve,2016-10033 reference:cve,2016-10034 ...
0
votes
4answers
41 views

How can I remove repeated lines taking into consideration the text from just a column?

I have the following file: ICR1 + ICR1+1+3199 + ICR1+2526+2828 + IRT1 + IRT1+1+1489 + IRT1+713+937 + LSR1 - LSR1+1+1175 - LSR1+366+638 - NME1 + NME1+1+340 + NME1+2+118 + PWR1 - PWR1+1+941 - PWR1+724+...
0
votes
3answers
50 views

How to match for an empty string in a grep pattern search?

I have a set of files containing boot variables from several cisco switches in the network. I have an requirement to filter only the switches with the boot variable empty on the next reload and print ...
-3
votes
0answers
31 views

need to change the date format of various columns in a file [on hold]

Looking for standardizing the date format in CSV comma delimited file for various date fields in file. the date field formats are not same but the standard format should be %Y-%m-%d %r.
0
votes
2answers
32 views

Find all lines containing only the same character and replace with the same amount of another character

My goal is to convert a NEWS format (the output of appstream-util appdata-to-news) to a markdown format (to use on GitHub/GitLab). A good approximation for me would be to just go from this: Version ...
2
votes
1answer
52 views

Prepend line that contains {} in files recursively using find and sed

I want to prepend recursively all files ending with .ts with this text: export {}; and I need to exclude at least the folder node_modules. I tried: find . f ! -path '*/node_modules/*' -iname "*.ts" -...
0
votes
3answers
45 views

Linux sed command replace two lines having spaces and special characters using regular expression

I have one file having following example text. "list-value": { "object-value": { "value": "example-value-123" } } I want to change value text "example-value-123" by matching pattern ...
0
votes
3answers
59 views

Replace last two occurences of commas with dots

In each line in I want to replace last two commas with dots I found such two sed piped method but it does not work with sed on MacOS $ echo 'abc,def,12379,foo' | sed 's/\(.*\),/\1./'|sed 's/\(.*\),/\...
1
vote
4answers
82 views

sed find and replace html tag

I need find and replace in a md file (plain text) <span class="symbol">&#58771;</span> with this: [&#58771;]{custom-style="symbol"} I tried many times, f.e. sed -i -e 's/\(&...
1
vote
3answers
56 views

How to remove the summary at the beginning of the “top” command in Linux?

I used top -b -n 2 | awk '{if ($9 != 0.0) print $0,sed -n '8,20p'}'>>text.txt , then the output is : top - 16:24:42 up 3:49, 3 users, load average: 0.23, 0.29, 0.31 Threads: 503 total, 2 ...
3
votes
4answers
203 views

Replace a string in a file preceeded by another string

I have a bunch of config files looking as follows: reader_0 = newcamd({ name = "Oct 1", host = "hostname 1", port = 27020, user = "UNAME", pass = "password1", key = "0102030405060708091011121314", })...
1
vote
1answer
98 views

Can sed produce output in the form of text file(s) all by itself as long as the input came from STDIN?

What the title says: assuming sed reads from STDIN1 could its output be a text file ? Just to be clear, I'm not talking about saving sed's output to a text file via shell operators like >, >> ...
0
votes
2answers
26 views

Renaming part of name of all files in a directory tree if match

I have a directory tree like this . |-- players | |-- red_alice.plr | |-- red_bob.plr |-- resources | |-- red_cash.rsc | |-- red_food.rsc I want to go through all directories and rename any ...
0
votes
0answers
48 views

Remove Partial Duplicates in Shell Scripting

831177 830372 831177 830373 831178 831177 831178 831177 830373 830372 831958 827391 832226 824442 834434 833887 I've first line combination in 4th line and 2nd line also in 4th line I want the ...
0
votes
3answers
52 views

awk + count strings in file

we have huge file like this this is partial list in the file Topic: Ho_HTR_bvt Partition: 31 Leader: 1007 Replicas: 1007,1008,1009 Isr: 1009,1007,1008 Topic: Ho_HTR_bvt Partition:...
0
votes
3answers
29 views

using awk to modify field with condition

INPUT New,9,1 Old,11,0 OUTPUT New,09,1 Old,11,0 I would like to append to filed number 2 after first , in case if it's single digit so i would like to add 0 before the digit as the output shown. ...
4
votes
3answers
145 views

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

root@u1804:~# sed --version sed (GNU sed) 4.5 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free ...
2
votes
2answers
72 views

How to replace a single similar line only AFTER a match [closed]

I am trying to search for a specific item [7_addons] and ONLY replace the NEXT entry that appears from enabled=0 to enabled=1. in this example: sed -i -e 's#enabled=0#enabled=1#g' /etc/file.txt .....
2
votes
1answer
63 views

How to use the a and i command in Gnu sed to add a newline character using \n?

In below example, I can use the literal newline characters to add an empty line before and after 3. Is it possible to use \n instead? I'm using Gnu sed 4.5. root@u1804:~# seq 5 | sed -r -e '/3/{i\ &...
2
votes
1answer
22 views

Run sed without -n, will the d command skip the default auto print pattern space content?

The document of sed states that d will: Delete the pattern space; immediately start next cycle. If sed is run without -n, will sed auto print the pattern space after a d command? I know at this ...
1
vote
1answer
20 views

How to prevent from destroying symlinks, using Perl when to replace with sed regex?

Based on How do I prevent sed -i from destroying symlinks?, but I use Perl. I tried by middle of all these questions: Is there a way to make perl -i not clobber symlinks? perl symlink on gz file How ...
6
votes
1answer
79 views

Any way to have a “verbose mode” or “debug mode” with sed?

Is there a way to make gnu sed be verbose about what is run and what is done ? I'd like to have something like a "debug mode" so that I can see - for each line of input - the content of the hold space ...
2
votes
1answer
78 views

How to use the w command of sed and write to file?

Below is my testing. How can I fix the error? ubuntu@u1804:~# sed --version sed (GNU sed) 4.5 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://...
1
vote
1answer
45 views

Using sed to replace the hexadecimal code for URL and to insert new SVG codes after SVG tag in all SVG files

I would like to ... replace the hexadecimal code for URL (id) in all SVG files insert/add the new lines of SVG codes after <svg ...>, using Regex. Input: <svg xmlns="http://www.w3.org/...
7
votes
3answers
397 views

Awk - replace one character only in a certain column

I have a file like this: 2018.01.02;1.5;comment 1 2018.01.04;2.75;comment 2 2018.01.07;5.25;comment 4 2018.01.09;1.25;comment 7 I want to replace all dots . in the second column with a comma , as I ...
0
votes
3answers
47 views

Extract particular string from stream

I have a file in which snort signatures are stored, I need to extract Bold ones "sid" and CVE number from that signature, here is a sample signature alert tcp $EXTERNAL_NET $HTTP_PORTS -> $HOME_NET ...
2
votes
4answers
58 views

SED delete csv column if exists

I need to remove a column from my tabulated CSV file if this column exists. My CSV file: GENE REF ALT AKT A G AKT G G Desired output: if column REF exists delete this column GENE ALT AKT ...
0
votes
3answers
38 views

unix awk match a string and perform delimiting

I'm checking the ping connectivity checks from a host and that would ssh to another jump host and will perform ping communication. I would like to print the successful packets pinged count using awk. ...
4
votes
6answers
108 views

How to edit the entire file after match a grep pattern?

To simplify, I want to edit the whole file after matched pattern, example of a file: $ cat file ip=x.x.x.a mask=255.0.0.0 host=a ip=x.x.x.b mask=255.0.0.0 host=b ip=x.x.x.c mask=255.0.0.0 host=c ip=x....
-1
votes
3answers
69 views

how to find & replace a file path listed in a file

I have a file content as shown below. If a line has ".idt" word, then I need to check if there is a file path preceding it (eg: /bin/dir/test/abcdef.idt). If yes, then remove the file path and keep ...
1
vote
1answer
23 views

Disable Tomcat Session persistence using sed or perl

I need to disable Tomcat session persistence as I have implemented SpringSession on my Spring (not Spring Boot) Application. I've tried using sed and perl to edit multiple lines in the context.xml ...
3
votes
2answers
77 views

Remove even numbered lines of text file [duplicate]

I have a text file on a Linux system, and would like to remove every second line, which is "even" numbered. Example: I would like to remove the second line of the file, the fourth, sixth, eighth line, ...
2
votes
1answer
23 views

How to change data file format from Gnuplot to Tikz errorbars

I would like to change the format of Gnuplot errorbar data to LaTeX/Tikz format. For example, the Gnuplot format data is: 5 74.92725 74.7028332590511 75.1516667409489 112.5 112.55897 112....
-2
votes
1answer
53 views

Show only lines which contain numbers [closed]

I have a file with the following lines: irakli1 iraklikairakli ikarkalsi1 iarksldisrii3 irakli and I want to show only the lines which contain numbers. I tried this but it is not working: sed -n '/...
2
votes
4answers
109 views

Replace AWORD or BWORD with CWORD in sed

So I have a list of random websites of the following kind: rapido21655bonk.a.sweetpotato.net rapido26230bonk.a.sourpotato.net rapido29926bonk.b.sourpotato.net rapido29926bonk.b....
0
votes
0answers
13 views

Interaction of sed and for loop [duplicate]

for i in {1..25}; do cat file$((i)) | sed 's/.*/$((i))/'; done doesn't print the current value of i but just $((i)). How can I make it print the value of i instead?
0
votes
3answers
56 views

removing “na” from a column and collapsing the row

I would like to remove rows that have an "na" file 0.000 0.000 0.055 0.036 0.003 0.002 0.000 0.002 0.002 0.002 0.000 na na 0.000 0.000 na 0.002 0.002 0.003 output 0.000 0.000 0.055 0.036 0.003 0....
-3
votes
1answer
61 views

How to replace value in each field until a certain character in each record?

Each record coming with column names. I have to replace them in each record as shown below: TIME=20181219110000275|CHAN=FMBKHJBAAAADPCFNAAAAAABA|EVNT=SWIgrld|API=SWIrecGrammarActivate|TYPE=uri/2.0|...
0
votes
2answers
32 views

Multiline string replace inside markup tag

I am trying to modify an httpd.conf file, allowing override in the /var/www/html directory. For simplicity's sake, let's say it looks like this: <Directory "/var/www/html"> # Comment ...
0
votes
3answers
63 views

Move line that matches pattern to top of file (multiple files)

I've got a folder containing roughly 4000 text files, each of which contains an email and its headers. I want to convert all the files in the folder to one .mbox file, but to do that I need every ...
0
votes
2answers
41 views

Counting the number of lines between same repeating pattern

I have refer this Grep the lines between the occurrence of the same pattern , I don't want to split into file; instead, I want to store it into an array. File count.txt contain: 0 1 2 3 0 1 2 0 1 ...
-1
votes
0answers
62 views

bash: find exec in a subshell with multiple commands

I am using find and then executing a set of commands in a subshell as follows: find ${CWD} -name "Sourced.sh" -exec bash -c '\ i="$1"; echo ${i}; \ cat ${i} > ${i}.temp; \ "${dScriptP}"/Substitute....
0
votes
1answer
56 views

sed or awk for formatting

I have one text file which consists of group of contact numbers with names like below. sam=12345,john=98765,bruce=67890,jack=54321,nick=23456,noah=67894,vision=65432,thor=98768,tony=89769,cap=...
0
votes
2answers
41 views

Find files (not) containing text pattern on a specified line

I'm trying to search through a set of text files and return the names of files that on a specified line contain a text pattern OR do not contain the text on the specified. In my case I need to return ...
0
votes
1answer
31 views

automatically repair rsnapshot config: replace spaces with tabs

rsnapshot is quite picky in its config: the commands have to be separated by TABs and not spaces. if you use rsnapshot configtest you see the errors, but how can I automatically repair the errors ...