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

learn more… | top users | synonyms

3
votes
1answer
51 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 ...
12
votes
7answers
2k views

How to delete every second line from a file?

File: Data inserted into table. Total count 13 No error occurred Data inserted into table. Total count 45 No error occurred Data inserted into table. Total count 14 No error occurred Data inserted ...
0
votes
1answer
26 views

Delete trailing commas in line

How do I delete a set of trailing commas in bash: a,b,c,d,,,, 1,2,3,,,, Desired Output: a,b,c,d 1,2,3 Tried doing this: grep "5628" test.csv | sed 's/,*$//g' but it doesn't work. If it ...
7
votes
7answers
299 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 ...
-1
votes
1answer
37 views

How to add a word at the first of every lines? [duplicate]

File1: Data will be inserted on Thursday Messages has been sent at 6pm Office hours is from 9am to 6pm All the employees are present Output what I want: DMS Data will be inserted on ...
6
votes
5answers
439 views

reverse order of paragraphs in file

I have a file containing text in paragraphs (lines with text separated by one or more empty lines). I would like to reverse the order of paragraphs (i.e. last paragraph will become the first, ...), ...
1
vote
3answers
45 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
3answers
490 views

Get last set of non-empty lines

I'm running a cron job which should get only the last result of iostat -d 1 2. This requires some parsing: What is the simplest way to get the last set of non-empty lines from standard input to ...
17
votes
11answers
3k views

There must be a better way to replace single newlines only?

I am in the habit of writing one line per sentence because I typically compile things to LaTex, or am writing in some other format where line breaks get ignored. I use a blank line to indicate the ...
2
votes
3answers
60 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
45 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 > ...
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. ...
4
votes
2answers
582 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 ...
94
votes
3answers
195k 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
49 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
134 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
21 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
195 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
174 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
235 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 ...
3
votes
3answers
45 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
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!!! ...
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
40 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
65 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 [closed]

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
41 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
46 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
33 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
136 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
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 ...
-1
votes
1answer
40 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
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
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 | ...
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
282 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
42 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
111 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
102 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
68 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 ...