sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

6
votes
3answers
191 views

How to print a line if that line or the next line do not contain a particular string

Input.txt: 8B0C remove 8B0D remove 8B0E remove 8B0F 8B10 remove 8B14 remove 8B15 remove 8B16 remove 8B17 remove 8AC0 8AC1 ...
0
votes
3answers
45 views

How to print empty spaces in first column using awk or sed

Here is my sample input file. ip.txt: john math science paul math science rosy math jill science rob math science hary math Desired output: john paul ...
1
vote
2answers
53 views

Remove x lines before and y lines after nth line (which matches a pattern) in a file

I'm trying to remove a four line block from a text file if the second line matches the Regex N+. The text file is composed of many repeating 4 line formats, ie: @HEADER1 ACTGCNNNT + 583@#!NMY ...
1
vote
2answers
99 views

how to replace a sed/perl expression (change and print only matched line) with a python expression?

I have asked this question to learn how perl could replace sed. Now I want to know how the following commands (which do the same thing) would look like for python: sed -n ...
1
vote
1answer
75 views

how to replace a sed expression (change and print only matched line) with a perl expression?

I am trying to move to perl (from sed). But how can I replace this sed expression with perl in a similarly short way? sed -n '/patternmatch/s%stuff%changed%p' file The only way I could do it was ...
1
vote
2answers
32 views

Sed Replace Around Numeric Content

I'm modifying an html output <td nowrap align="right">4683</td> I'd like to replace all occurrences in the document matching this pattern, where 4683 may be any given number varying in ...
11
votes
9answers
2k views

How can I delete the 5th word of every line in a file?

I want to delete the 5th word of each line in a file. The current content of the file: File is not updated or and will be removed System will shut down f within 10 seconds Please save your work ...
2
votes
2answers
221 views

Replacing a captured group using SED

xxxxxx15 |xxxxxx02|RM99999 |xxxxx |Ankur |xxxxx |xxxxxxxx|M|xxxxxxxx| | | ...
1
vote
5answers
94 views

How to get all numbers out of a string and add them?

I have to parse a .xml file generated to summarize the results of a running a testSuite on some software. In a line I have, for example: <Summary failed="10" notExecuted="0" timeout="0" ...
1
vote
3answers
76 views

how to break a line after matching a certain character using shell command?

File1: John Daniel Hommes Cameron;Emily Terry Mussy Barbara Mimi Papu;David Swiss Jen Hans Peter Iril;Kelvin Lilly Gucci Kate Nik;Forum Bill June;Jill and Jack Output file: John Daniel Hommes ...
0
votes
2answers
63 views

How to count the number of words of each sentences in a file using shell command?

I have text files like this: Mr.P.K.Baneerjee has visited the site today at 4.30pm The permit tag has been set in the ds busbar Opearation has been performed in presence of control engineer Opeation ...
1
vote
2answers
71 views

How to extract 1st, 3rd, 5th of group of three lines by sed or awk?

Say I have a file: Line1 Line2 Line3 Line4 Line5 Line6 Line7 Line8 Line9 Line10 Line11 Line12 … I want to get: Line1 Line2 Line3 Line7 Line8 Line9 Line13 Line14 Line15 It means that I want ...
6
votes
2answers
241 views

Sed remove all beginning pattern matches from line

I have the following line: abababtestab I'm trying to figure out a sed expression to remove all occurrences of ab from the beginning of the line so the transformed line should be: testab I feel ...
-1
votes
1answer
76 views

how to extract lines between 2 patterns, and save them to different files

hej all, Let' say that we have this file: rrows 35 cols 51 spin 2 %band5 efermi=0.012538 0.004352 0.004317 0.004213 0.004047 0.003828 0.003570 0.003291 0.003011 0.002754 0.002544 0.002408 ...
3
votes
3answers
122 views

Undo letterspacing with sed

I have a source text file containing text where some words are l e t t e r s p a c e d like the word "letterspaced" in this question (i.e., there is a space character between the letters of the word. ...
2
votes
2answers
61 views

print empty line in sed output when passing multiple filenames

I'm doing some placeholder replacements in various files that I'm feeding to ldapadd, to add new entries to an LDAP directory: sed \ -e 's/%%FOO%%/whatever/g' \ -e 's/%%BAR%%/other thing/g \ ...
0
votes
1answer
50 views

Merge the duplicated lines and add “N/A” in the end [closed]

I have the following lines in a text file. I want to Merge the duplicated lines and add "N/A" in the end of the line to have six columns 302C21;tSMe S123C;1.17 302C21;2;346;SM-1-3/SM-1-4 ...
0
votes
1answer
45 views

sed - find and replace text containing “/”

How can I search and replace text that contain / with sed? I currently use the following which doesn't work sed -i "s/queue_directory = /var/spool/postfix-secondary/queue_directory = ...
3
votes
4answers
92 views

Print alternating lines with conditional

Still struggling with messy logfiles. What I want is to find lines that first matching string X and then string Y. I then want to print them together. The problem is that, sometimes there is X, but no ...
2
votes
2answers
56 views

Truncate the third column until given strings

INPUT: W41784094 CH60104475 lasbalsrbla bla foo bar bla PT~CH60104475 W41788464 WO60444453 hellobla bla -bla foo bar 432 alaf. PT~CH60107925 W41753387 IN61026681 sim##bla-bla bla foo bar ...
1
vote
2answers
38 views

find a field and move it to before the end of the line

I have the following line and I want to find the field contain "ABCD" and move it before the end string1;string2;xxxABCDxxx;string3;string4;string5;string6 Output ...
2
votes
4answers
241 views

Replace values in column that contain numbers

I have a file that looks as so: chrom start stop strand isoform mu_codon mut_codon2 more_info chr22 43089055 43089055 - NM_017436 C 300 903delC chr22 43089715 43089717 ...
1
vote
3answers
128 views

Remove characters in a specific column before a specific character

I have a file that looks like so: chr22 43089055 43089055 - NM_017436 C 300 903delC chr22 43089715-43089717 43089715-43089717 - NM_017436 CTT 79 I want to remove all the ...
0
votes
3answers
87 views

Removing white space using sed but skipping Date-Time stamp

I wanted to remove white space from a CSV file, which I am able to do using s/\ //g, but at the same time I want to avoid removing the space between fields which has timestamps e.g. "06-JAN-15 ...
1
vote
3answers
92 views

Merge duplicated lines which have the same fist three filed

I have the below input (thousand lines). I want a sed command to merge duplicated lines with the same fist three filed but adds only different fields and delete N/A: D04005;4;279;0;0;SSM-4-1 ...
3
votes
2answers
129 views

To count number of matches in a mega string quickly

I have big text-data without spaces and without other rows in one line. In reality, the streams are 0.2 Gb/s, similar situation here, but in this task, counting occurrences which is more challenging ...
0
votes
1answer
68 views

What is the cause of the sed error?

In my grunt file I have the command like this "sed -i index 's/API_CONTEXT_URI/http:\\/\\/localhost:5557/g' www/index.js" This is not a file I have written; this has to come to me as a maintenance ...
-1
votes
1answer
51 views

To sed if with and without conditions correct

I know that I may have the C package #include <stdint.h> in the first 1-30 lines. I would like to add it to lines where no previously if the file contains the word LARGE_INTEGER by GNU tools. ...
1
vote
2answers
54 views

Exec condition and xargs in Find simultaneously

I am trying to include the standard C package stdint.h to files which have the word LARGE_INTEGER, as a part of conversion from Windows to Linux drivers as discussed here for datatypes. I know the ...
0
votes
1answer
51 views

Using sed to replace special characters

This works to replace tom with sam in a file: sed 's/tom/sam/g' file_1 > file_2 But this does not: sed 's/*****/sam/g' file_1 > file_2 To replace the special characters ***** with the word ...
0
votes
1answer
54 views

How to extract particular fields from lines using shell commands?

File1: 27/07/2014 10.10.03 Breaker1 was closed by Mr. A.Basu Spectrum ui6dms 29/07/2014 04.50.53 Breaker1 was opened by Mr. D.Gupta Spectrum ui6dms and one note added 30/08/2014 03.20.01 EarthSwitch ...
3
votes
1answer
164 views

GNU Find this but not that and do Sed?

Code find /tmp/ -type f \ \( -name "*.h" \) -o \( -name "*.cpp" \) -o \ \( \! -name "*.bak" \) -exec \ sed -i ...
2
votes
2answers
54 views

Sort a list and separate item with commas instead of newlines

I want to list all the filesystems in a single comma-delimited list, in dictionary order. I'm using this command: cat /proc/filesystems | sed 's/nodev//' | sed 's/,$//' And my output looks like ...
-1
votes
2answers
76 views

select portion of file by line interval [duplicate]

I want to practice using head, uniq and cut, for this data here. I know this thread but it focuses too much on cat and external programs. I would like a simpler answer. I want to take interval from ...
0
votes
3answers
49 views

How to subsitute a string in file with another file?

I have a bunch of files that all contain a string. This string needs to be replaced by the whole content of another file (that can possibly be multiline). How can I do so? What I need is something ...
2
votes
1answer
27 views

Extract values from block of data

I have the below block of data. Heap after GC invocations=31 (full 3): par new generation total 131008K, used 0K [0x00000000eac00000, 0x00000000f2c00000, 0x00000000f2c00000) eden space ...
2
votes
2answers
43 views

sed and string of data

I need to print the data starting from the line that matches Data after AB process=1234 (full 10): till end of the file. Could you help please. I tried putting the data in a variable called "value" ...
-1
votes
2answers
26 views

To sed match and some text in newlines

You want to visualize maximum 10 marks but minimum 1 mark after the sequence 65 72 62 65 in a newline where the dummy data source is hexdump -v /usr/bin/telnet and the less is a viewer. Code hexdump ...
3
votes
2answers
85 views

Compare 2 Files if it falls between a range of numbers

I have 2 files, File 1: 4 7 2 File 2: 1 5 Alpha 6 10 Bravo 11 15 Charlie 16 21 Delta 22 30 Echo I want to compare every entry in file 1 if it lies between col 1 and col 2 of file 2 (should be ...
5
votes
5answers
280 views

Converting long numbers to hex with sed

I'm trying to make a sed command so that numbers longer than 3 digits were converted to hex. I.e. a string like 124 3275 7535 should result in 124 0xccb 0x1d6f. Here's what I currently have: sed ...
1
vote
2answers
41 views

Extract lines from a file using vim or teminal

I have the following in a file. I'd like to use Vim or terminal to extract title and its content like this. How can I achieve this? Topic 1 - Core: Algebra 1.1 Arithmetic sequences and series; sum ...
-1
votes
3answers
87 views

sed - Remove lines that contain “hotmail” in the third field

I am trying to delete all emails that contain the word hotmail in the third field from my .txt file. I am currently trying to use the following but it only deletes some lines. I am not sure why sed ...
0
votes
1answer
76 views

Remove the exact same matching lines with sed

I have this bash script: sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie main/d' /etc/apt/sources.list sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie\-updates main/d' ...
2
votes
2answers
246 views

Slash and backslash in sed [duplicate]

I want to use sed to change a slash into a backslash and a slash, i.e. / -> \/. But it does not work. Here a small example: #!/bin/bash TEST=/etc/hallo echo $TEST TEST=$(echo $TEST) echo $TEST ...
3
votes
5answers
156 views

How to add column in the beginning of file using perl?

I want a Perl one-liner that checks whether the first fields of an input file is the file's name and, if it isn't, adds the file name as the first column on every line. Example written in shell : ...
8
votes
3answers
446 views

sed - how to capitalize every 3rd word?

Given: main_east_library main_west_roof main_north_roof minor_south_roof How can I used sed (specifically, not awk, tr, etc.) to create: main_east_Library main_west_Roof main_north_Roof ...
-1
votes
1answer
35 views

Using sed to replace a string with the last character unspecified?

I want to use sed (or any method) where I replace a string in a file. The string is of the format "prv=x" where x is some integer. Is there a way in sed that I can designate this entire string to be ...
8
votes
9answers
610 views

awk or sed to lowercase/uppercase only one character in string?

Is there a way how to uppercase/lowercase only one character in some string? Input Example: syslog_apr_24_30 syslog_mar_01_17 Desired output: syslog_Apr_24_30 syslog_Mar_01_17 Note please the ...
-3
votes
2answers
43 views

sed or awk to get a string

I have a shell script with string=<deploymentTargets xmi:type="appdeployment:ClusteredTarget" xmi:id="ClusteredTarget_143378365 7353" name="cluster1"/> I want the value between name=" and ...
8
votes
1answer
213 views

What is the point of using multiple exclamation marks in sed?

POSIX sed documentation said: A function can be preceded by one or more '!' characters, in which case the function shall be applied if the addresses do not select the pattern space. Zero or ...