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

learn more… | top users | synonyms

0
votes
0answers
12 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 ...
1
vote
0answers
17 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
48 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
31 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. ...
0
votes
2answers
30 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
33 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
33 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
38 views

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

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
28 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
57 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
17 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
21 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
64 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
247 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 ...
0
votes
0answers
32 views

How to get the placeholder's value which is stored in a different file (same directory) [closed]

With the conditions: I cannot use any XML parser tool as I don't have permission , read only My xmllint version does not support xpath, and I cannot update it , read only I dont have xmlstarlet and ...
-1
votes
3answers
74 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
48 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
159 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
103 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
411 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
416 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 ...
7
votes
1answer
175 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
151 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
344 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
29 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
2answers
57 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
25 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
38 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 ...
0
votes
5answers
85 views

Print everything between two patterns, then delete first and last line of the resulting output

otherdata otherdata start_data one two three four end_data otherdata otherdata The resulting output should just be: one two three four This looked like a job for sed to me: sed -n ...
6
votes
1answer
105 views

How can I extract/change lines in a text file whose data are separated into fields?

How can I manipulate field-based data from the commandline? For example How can I print only lines whose Nth field is foo? How can I print only lines whose Nth field isn't foo? How can I print only ...
1
vote
3answers
46 views

Delete lines that contain X in specific column .csv [duplicate]

I currently use the following to delete all emails that contain EXAMPLE sed -i '/EXAMPLE/d' newname.csv However that deletes lines that have EXAMPLE in any of the columns. I want it to only delete ...
1
vote
2answers
59 views

Keep line that contains X within the first two fields

I have a .txt converted from .csv that looks like this Smith","example","example","example","example" example","Smith","example","example","example" example","Smith","example","Smith","example" ...
3
votes
6answers
114 views

Case-insensitive count duplicate line, remove duplicate by choose case with highest duplicate

The duplicate is combination of different case text. I need to count number of duplicate (case-insensitive) and then I need to remove duplicate by choose case with highest duplicate. Below example: ...
4
votes
4answers
479 views

How to insert all lines from one file to another file?

File1: .tid.setnr := 1123 .tid.setnr := 3345 .tid.setnr := 5431 .tid.setnr := 89323 File2: .tid.info := 12 .tid.info := 3 .tid.info := 44 .tid.info := 60 Output file: .tid.info := 12 ...
1
vote
5answers
87 views

Only keep .csv column containing X Y Z data?

How can I keep .csv line data that only contains the words dog or cat and only check for them on the second column, if the word "dog" appears on any other column but not the 2nd then it should be ...
1
vote
2answers
26 views

How to truncate a HTML link?

INPUT: <a href="docs/2015-05-foobar/foobar.sh">foobar.sh</a> OUTPUT <a href="foobar.sh">foobar.sh</a> Question: How can I remove the "docs/2015-05-foobar/" ? The string ...
0
votes
2answers
23 views

Unable to perform a simple multiplication in script

I am havingf trouble performing a simple multiplication in my script. while read A B C do tmp=$A\*$C/100 echo $tmp >> out1.txt done < foo.txt foo.txt: 13721725 99 100 ...
7
votes
6answers
180 views

How to efficiently split up a large text file wihout splitting multiline records?

I have a big text file (~50Gb when gz'ed). The file contains 4*N lines or N records; that is every record consists of 4 lines. I would like to split this file into 4 smaller files each sized roughly ...
2
votes
4answers
71 views

Change text in tag, but only tag is contained within a certain XML block

Using Git Bash, I'm trying to conditionally replace what's in the yrot tag in hundreds of files, but only if it belongs with a part name tag that pertains to wheel. // YES, change <part ...