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

learn more… | top users | synonyms

-1
votes
0answers
27 views

Escape in awk invoked [on hold]

Using this line: sed -i 's/\t*$//' file_a > file_a I would need to incorporate in R in the system command (to execute it in a loop). I know that the escape is / but: system(paste("sed -i ...
-3
votes
0answers
23 views

Find the number of jobs present in each box. Find the number of child box in each parent box [on hold]

BOX_A--------------------SUCCESS JOB_AA--------------------SUCCESS JOB_AB--------------------SUCCESS JOB_AC--------------------FAILURE BOX_B--------------------FAILURE ...
3
votes
3answers
110 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
49 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
47 views

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

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
33 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 = ...
2
votes
4answers
61 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
35 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
30 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
138 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
58 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
54 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
91 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
124 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
54 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
43 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
43 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
39 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
47 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
143 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 ...
-3
votes
1answer
43 views

sed/awk - replace first occurance of a string with array of strings [closed]

I want to find the first occurrence of a word and replace it by 3 strings using sed/awk. for example , I have the below entry in my /etc/hosts file 10.4.16.11 dispatch1 10.4.16.12 dispatch2 ...
2
votes
2answers
36 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
58 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
45 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
18 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
41 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
23 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 ...
2
votes
2answers
66 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
251 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
36 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
75 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
52 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
162 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
107 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
420 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
28 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
437 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
39 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
192 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 ...
4
votes
4answers
157 views

How to remove newlines between data of each record which are located between 2 patterns?

I have a large file to parse and reformat, preferably with sed (under bash). The file contains repetitive sequences starting with PATTERN_START and ending with PATTERN_END. These sequences are ...
1
vote
1answer
20 views

calculate numbers on end and merge to one line

So in a file i have lines like these: thisdata:thisother:1337 thisdata:thisother:1800 thisdata:thisother:1500 thisdata:thisother:46984 I would like to output: thisdata:thisother:51621 for all ...
-1
votes
1answer
17 views

Matching 2 different files by first column

So I have 2 different files. file1.txt is: abcdefjeiireiiioe:data:otherdata rijirjeiwrieeoooe:datamore:otherdatamore file2.txt is: abcdefjeiireiiioe:data:otherotherdata ...
7
votes
7answers
345 views

Removing numeric values in certain columns whilst keeping minus signs?

I put my hands up to being a complete beginner, so apologies if I'm doing this wrong. Say I have the following data frame that continues indefinitely horizontally and vertically with negative numbers ...
2
votes
4answers
44 views

Sum of alternate values in a column using either sed or nawk

foo.txt: 1 10 11 2 20 22 3 30 32 4 40 42 5 50 52 6 60 62 7 70 72 8 80 82 9 90 92 10 100 110 Desired Out.txt : 1 10 11 2 20 22 3 ...
-1
votes
1answer
31 views

Why sed replace all occurences instead of first occurence? [duplicate]

I'm trying to replace the first occurrence in a file using sed: sed -i s/he/He/ dummy.txt Instead of replacing first occurrence, it replaces all the occurrences, even without /g. According to ...
0
votes
1answer
32 views

Convert particular lines in a text file to bold [closed]

I have a text file with 100 lines in it. I want to convert particular lines, lets say line1, line6 , line27, line 48, line 86, line99 to bold. I am using solaris 5.10, with KSH. Is there a way I can ...
2
votes
2answers
36 views

Awk - keep word “example” and “EXAMPLE” with one input

I am attempting to to only keep customers that contain certain words. Here is an example < newname.txt awk 'BEGIN {FS=","} $7~/USA|United States/' > usa.txt The problem I am having is if they ...
0
votes
3answers
61 views

Bash to match two variables for time difference

I have a bash command which gives me following result (Fetch user account details from the mysql using command select creationdate from users; Name Account Creation Date Mobile User1 ...
0
votes
2answers
27 views

Sed to keep header(s) line(s) + matching lines

I have not found (nor been able to guess) a sed command that would allow me : To keep : specific lines according to their index (the header for instance) To keep : lines matching a pattern (like ...
0
votes
4answers
40 views

How to remove 0 from the second column in a file

I ahve a script which fetches user name and mobile from a file in following format **Current Format** username mobile zzz 03333012345 123 03212334343 245 ...