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

learn more… | top users | synonyms

2
votes
3answers
55 views

Extract specific value from blocks of data

I have the blocks of data which are differentiated by the global Ids as below. I need to extract the last block of data with the highest id value, in the below example, id="82". <gc type="global" ...
1
vote
1answer
37 views

error in awk/sed usage of file manipulation line-by-line [duplicate]

I have a requirement of appending the string " 1" at the end of every line of the file. After the execution of below two commands, an empty file is created. awk '{ print $0 " 1" }' < file.txt > ...
1
vote
3answers
40 views

Adding a pattern to each field of the following line

I need some help here please. I have the following input: MX04A; DMX04A; DMX04A; LMX04A; LMX04A; -17.2; -15.3; -14.3; -13.6; -16.8; -15.4; -16.0; -15.3; LH36A; DLH36A; DLH36A; -11; -117.2; -11; ...
2
votes
5answers
70 views

bash expanding to same value instead of line by line value in sed command

I have a file containing numbers in it say numbers.txt as follows. 9374541632553 51243747879841 32030098896914 84654557358238 11000656847765 I want to convert it to the following format. ...
1
vote
1answer
18 views

Using Sed to replace n character before keyword including keyword?

For replacing everything before a keyword piece of code below works well. sed 's/.*keyword/string-to-be-replaced/' But for replacing n characters before the keyword including keyword I couldn't ...
2
votes
3answers
43 views

Regex search for word roots with common prefixes

I recently had a curiosity about words in the dictionary that share both "pro-" and "con-" as a prefix. So, for example, procession/concession, produce/conduce, profess/confess, progress/congress, and ...
1
vote
1answer
46 views

How do i insert a character at the beginning of each line of a paragraph that contains string

Sort of different request here, but i have a text file in which i need to place a @ character at the beginning of each paragraph (paragraphs=separated by blank lines) that contains a certain search ...
2
votes
2answers
18 views

How to replace value for a given condition in specific column of file

I have file separetd by pipe | and I want that when column 6 contain letter I print 0758000 in column 7 and when the column 6 contain letter A print 0800000 in column 7, I can not find how to do it!!! ...
2
votes
1answer
44 views

Grep on single line [duplicate]

I have a script that streams a pattern in a single line (no linebreaks). I want to grep stock_ticker in that line and output it as soon as I have found one. Now the script is never ending and is ...
0
votes
1answer
38 views

Bash : rewriting a file which is read in same line

I'm working on a bash script for partially automating router connection in command line. I'm a newbie in Bash. This is part where I have a problem: #!/bin/bash STRING2="ESSID" MYPWD=$(pwd) sudo ...
1
vote
1answer
57 views

Convert multilines to single line with SED

I need additional help, based on similar question I have located here: Convert multilines to single line Current SED example (sed -e'y/)},={/(((((/' \ -e's/-\([^(I]*\)[^0-9]*\([0-9]*\)[( ]*/- \2 ...
0
votes
1answer
39 views

Find part of String and replace entire string in a file

I have a file named A.xml which contains a strings such as "Ticket_Release1" and "Ticket_V2". I want to find and replace all the strings in the file starting with Ticket_ with something called ...
-5
votes
1answer
25 views

linux command use for sed [on hold]

Logs: 2015-07-22T00:00:19.075Z"6281578552406"120.164.45.41"Mozilla/5.0 (Linux; Android 4.4.4; SM-E500H Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.78 Mobile Safari/537.36 ...
2
votes
4answers
133 views

Is it possible, with `sed` or otherwise, to apply a regex transform to an input stream that may not contain newlines?

I have a shell pipeline that contains a sed expression: source | sed -e 's:xxxxx:yyyyy:g' | sink It works but it has a latent flaw because sed works on whole lines. This means that the sink will ...
0
votes
1answer
42 views

sed: extra characters after command

i have a text file and i want to remove all lines in it that have EXPRESSION_1 in them. I type sed 'd|EXPRESSION_1|' filename.txt > tempfile.txt and get the output: sed: -e expression #1, char ...
0
votes
1answer
28 views

sed - find string made of 4 numbers with a preceding character and append character

I'm trying to build a sed command that will allow me to search and replace some values in a large csv file. I have this column which contains years, like 2005 - 2006 2001 - 2003 and so on, but I also ...
0
votes
0answers
31 views

why this file not modifying? [closed]

sed -i "s/'${line[*]}'/'${newlinem[*]}'/" test2.txt I'm trying to replace whole line of my text file with new modified line. but my file not modifying with sed -i Both the above arrays are working ...
0
votes
0answers
32 views

Searching and replacing string using sed

Searching and replacing a string in a file. Input file name - Input.txt Following is the content: DATETIMEOFFSET(20) datetimeoffset(99) DatetimeOffset(10) lots of data1 lots of data2 ...
1
vote
2answers
32 views

Insert multi lines after match using Mac's sed command

I have 2 files:- a.xml <project> <modelVersion>4.0.0</modelVersion> <parent> ... </parent> </project> b.xml <project> ...
0
votes
1answer
62 views

How can I find and replace only in a range of columns?

I have a text file with 9267 lines. I want to find "A" with 5 spaces after it and replace it with "A" with 5 spaces before and after it on all lines, but only between columns 67 and 88. Text outside ...
-1
votes
2answers
47 views

Find file, Edit text within files

Im trying to find a file then edit the text within these files. This is what I have so far, but sadly Im not that well versed... Help Please? grep -rl "wrongtext" ~/Library/Calendars ...
2
votes
2answers
40 views

Grouping lines into heterogeneous subsets

I have file with n lines.  (Each line refers to a “question”, and therefore they are labeled Q.1, Q.2, Q.3, ..., Q.n.)  Each line (question) has a “Marks” attribute, which has the value 2, 3, 4, 5, or ...
5
votes
4answers
134 views

Remove lines from file up to a pattern, unless the pattern doesn't exist

I am attempting to write a filter using something like sed or awk to do the following: If a given pattern does not exist in the input, copy the entire input to the output If the pattern exists in ...
2
votes
3answers
60 views

Read a column from a file and append a specific column of another file

I have two files as such: fileA: Name,Site Name,Product UPEI,Product Name,NMS Flag,Product Model, SW FileB: NE_Name SW ABC 4.4 ASD 4.3 ... ... Note that ...
-1
votes
1answer
39 views

String replacement in sed

How to replace BINARY(any integer of 64 bit) with BYTEA: Example1: Input: BINARY(28) Output: BYTEA Example2: Input: BINARY(234) Output: BYTEA
4
votes
2answers
41 views

Adding a new column using information from subheadings

Replacing lines containing a pattern with sed Thanks to @don_crissti and @Archemar. I reckon my question is not a duplication of the above question. So here is an example of input. Edit: All ...
1
vote
1answer
64 views

To use Pandoc pipe data with AWK

Data ID | Size | Blocks -------|-----------|--------- 206 |80760288 | 157744 207 |80760288 | 157744 328 |241520288 | 471728 Wanted output by AWK ID |BlockSize | Size | ...
-1
votes
2answers
51 views

Substitute a string containing && with sed [closed]

I've wrote some script for automated technical acceptance tests. Since we're not allowed to write password in clear text, the script I used is associated with many variables, one of which is the ...
2
votes
2answers
67 views

sed multiple entries in one command to remove data

I am using the following sed command to remove emails that contain hotmail - Is it possible to check for multiple entries at the same time? Preferably load it from list.txt (one entry per line). sed ...
1
vote
2answers
18 views

sed remove command - Include upper/lower case

I am using the following command to get rid of lines that contain hotmail sed -i '/^[^\t]*\t[^\t]*hotmail/d' ./file The test data is "foxva****omes****","scott@hotmail.com","8*** ...
1
vote
2answers
73 views

How to remove characters of text in one line before specific character

How to remove a characters of text in one line before specific character I will remove characters to the left of the first letter "F" Example: null###F01|54646466|00K4234001|IFD|1990101 ...
1
vote
1answer
33 views

Helping with sed - remove specific lines with certain string

These are the contents of the text file: cat dog elephant cat lion cat tiger penguin penguin emperor zebra I want to remove the line contain just cat and retain cat lion and cat tiger lines. There ...
0
votes
1answer
40 views

Replace pattern with line from file using awk/sed [duplicate]

I have a file first.html which contains the following code: <tr> <td class="headerValue">One</td> </tr> <tr> <td class="headerValue">Two</td> </tr> ...
2
votes
4answers
265 views

Replace regex match with string containing match

I have a file with text as Afghanistan=+93 Albania=+355 Algeria=+213 American Samoa=+1 Andorra=+376 Angola=+244 It has all the country list and its dialing code. I want to replace: ...
0
votes
1answer
62 views

load bash comands from file one per line and execute them for each file in a directory

I'm trying to write a bash queue which will be able to load command set from a file and then execute each over set of files. prepared file should serve as a template for execution in manual bash ...
2
votes
4answers
56 views

CSV - Only keep certain entries

I have a bunch of data inside "" and separated by , - Example below of two lines "stampthisandthat.com","GANDI ...
5
votes
3answers
136 views

How to print a line if next line does not contain a particular string using nawk or sed

Input.txt: 8B0C remove 8B0D remove 8B0E remove 8B0F 8B10 remove 8B14 remove 8B15 remove 8B16 remove 8B17 remove 8AC0 ...
0
votes
3answers
35 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
45 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
88 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
72 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
31 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
211 views

Replacing a captured group using SED

xxxxxx15 |xxxxxx02|RM99999 |xxxxx |Ankur |xxxxx |xxxxxxxx|M|xxxxxxxx| | | ...
1
vote
5answers
84 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
71 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
52 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
69 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
213 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
74 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 ...