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

learn more… | top users | synonyms

0
votes
1answer
14 views

Adding a pattern to some specific field

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; LLH36A; LLH36A; -11; ...
2
votes
5answers
40 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. ...
4
votes
2answers
578 views

Passing parsed output of sed to find (in this direction)

Well, I think you can find dozens of questions on this platform how to pipe find output to sed, but I haven't found anything for the reverse direction so far. What I want to do is modify my input, and ...
93
votes
3answers
191k views

How can I replace a string in a file(s)?

Replacing strings in files based on certain search criteria is a very common task. How can I replace string foo with bar in all files in the current directory? do the same recursively for sub ...
2
votes
2answers
46 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 ...
2
votes
4answers
131 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 ...
1
vote
1answer
17 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 ...
4
votes
5answers
190 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 ...
4
votes
6answers
170 views

Extracting lines based on conditions

Each line in a comma-separated file has 5 fields. a,b,c,d,e f,g,c,i, j,k,c,m,n o,p,c,r,s t,u,c,w, x,y,z,aa,bb How can I extract the lines which have c in the 3rd field and their 5th field is NOT ...
2
votes
3answers
232 views

How to 'drop'/delete characters from in front of a string?

I have a string that I would like to manipulate. The string is H08W2345678 how would I be able to manipulate it so the output is just W2345678? Similarly if the I wanted to drop the last 4 ...
2
votes
3answers
39 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
4answers
102 views

How to use regex in sed?

I need to revoke the sudo access to the user using sed in scripts. I want to comment the user only if the line contains /bin/su - root Let us consider the file as below, in which I have to comment ...
1
vote
1answer
44 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
43 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 ...
5
votes
2answers
11k views

Using sed to extract text between 2 tags

I have a .xml file and I'm trying to do a "groupinstall" on a RHEL6 machine as there are several hundred libraries in that .xml file... (close to 16 000 lines). I'm therefore trying to extract the ...
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
54 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 ...
-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 ...
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 ...
0
votes
1answer
41 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? [on hold]

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
31 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 ...
5
votes
3answers
1k views

sed convert 4 spaces to 2

How does one convert 4 spaces into 2 spaces with sed? Is it possible? I found this but it converts tab to spaces: sed -r ':f; s|^(\t*)\s{4}|\1\t|g; t f' file
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> ...
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 ...
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 ...
5
votes
4answers
132 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 ...
-1
votes
2answers
46 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 ...
-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
2
votes
3answers
57 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
vote
1answer
63 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 | ...
9
votes
7answers
6k views

How to insert the content of a file into another file before a pattern (marker)?

File1 contents: line1-file1 "1" line2-file1 "2" line3-file1 "3" line4-file1 "4" File2 contents: line1-file2 "25" line2-file2 "24" Pointer-file2 "23" ...
0
votes
6answers
278 views

sed to replace with backspace

I have trail.txt, which contains spice netlist. Now I want to replace all expanded parameters to one line only i.e. remove + and append that line to previous line. trail.txt data + net06706 ...
7
votes
4answers
316 views

How to insert lines with numbers from X to Y into another file after line Z?

I created two files: echo -e "1\n2\n3\n4\n5" > 123.txt echo -e "a\nb\nc\nd\ne" > abc.txt I want to get the file 123.txt with the following contents: 1 2 3 b c d 4 5 So in other words ...
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 ...
3
votes
2answers
1k views

Replacing lines containing a pattern with sed

How can I replace a given character in a line matching a pattern with sed? For example: I'd like to match every line beginning with a letter, and replace the newline at the end with a tab. I'm trying ...
1
vote
3answers
109 views

Swap line containing pattern with next line

I currently have the following code which nicely outputs some information about the wireless networks around me: sudo iw wlan0 scan | sed -nr '/SSID: |signal: |primary channel: /p' | sed ...
2
votes
0answers
100 views

Bash - Convert escape character colored text to BBCode

I want to convert a terminal escape-character colored text file to BBCode colored text. For this i've created an Android logfile with logcat -Cd > /sdcard/logcat.txt. The -C switch adds the color ...
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
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 ...
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*** ...
6
votes
4answers
713 views

sed ranges aren't always able to match only one line

Consider the following range: 1,/pattern/. If pattern matches on the first line, the range matches for the whole file: $ cat 1.sh #!/usr/bin/env bash set -eu seq 1 4 | sed -rn '1,/'"$1"'/p' $ ./1.sh ...
1
vote
2answers
72 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 ...
4
votes
2answers
222 views

Reorder Multiple Line Blocks with Sed

I am trying to reorder generated output as follows; given a tex fragment as follows, I want to move the /^Constant/ down below /Dummies/, with the line before and after /^Constant/. Further, I would ...
2
votes
4answers
6k views

Extracting column from comma separated text

I have a long comma-separated delimited file with 20K lines. Here's a sample: "","id","number1","number2","number3","number4","number5","number6","number7" ...
3
votes
4answers
253 views

How to use sed command to modify a file's entry line by line in shell script?

This is my file1: #$BQ #{ VOL @home } #database daba #relation tcdeatid #copy 1 #{ version 0 } #opendb #clear #.lruno := 72 #.infno := 1 #.tid.noel := 101 #.tid.info ...
10
votes
7answers
20k views

How to read first and last line from cat output?

I have text file. Task - get first and last line from file after $ cat file | grep -E "1|2|3|4" | commandtoprint $ cat file 1 2 3 4 5 Need this without cat output (only 1 and 5). ~$ cat file | ...
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 ...