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

learn more… | top users | synonyms

-1
votes
1answer
51 views

Replace a string with “string|string”

I have a pretty weird problem. I did some calculations for bioinformatics, but my downstream apps won't accept my header information in its current format. In order to circumvent this I modified my ...
0
votes
1answer
37 views

How to SED with open boundaries? [duplicate]

I was thinking too complicated the slicing in the How to express variables efficiently for SED? I want to include (a,b), not [a,b] like this don_crissti's command: sed ...
0
votes
1answer
42 views

How to express variables efficiently for SED?

There are many ways to express arithmetic things: new and old ways. However, I would like to write this line efficiently and well sed -n '$START,$ENDp;$ENDq' < data.tex which output sed: 1: ...
1
vote
3answers
129 views

Replace arbitrary characters in the middle of an IP address string with sed

I need to find and replace either one or two numerical characters in strings in a file. The strings are IP addresses of the form: 10.xx.y.z Where xx can be one or two characters. I want to ...
2
votes
4answers
115 views

How to add hyphens at the first empty line of a text file?

I'm trying to add three hyphens to the first empty line of a given text file, and am trying to use sed for this. My initial file (a MultiMarkdown file) looks something like this: title: "Ch. 1: ...
0
votes
2answers
36 views

How to get the sed command to only search for full words?

I'm fairly new to Linux and recently started experimenting with the command line. I decided to make a file and called it 'hi.txt'. The contents of the document was: This is hi.txt. hi hi hi I ...
1
vote
2answers
38 views

Reading a variable-sized line and splitting its content into separate lines with text

I have a file with the header (first line) with a variable length; and it comes as: "One"|"Two"|"Three" or "One"|"Two"|"Three"|...|"One Hundred" and want to get do a loop that transforms it ...
4
votes
4answers
640 views

Replace “/” with “\/”

I have a string /tmp/testing which I want to replace with \/tmp\/testing sed works fine as follows: echo testdir=/tmp/testing | sed 's/\//\\\//g' testdir=\/tmp\/testing However if I try and put ...
1
vote
3answers
59 views

how to remove first occurrence of 0 in mm/dd a date using sed?

I want to remove first occurrence of 0 in mm/dd, e.g. I want to make 09/09/15 look like 9/9/15. I have tried using echo 09/10/15 | sed 's/^.//' but it gives output like 9/09/15. How can I do this?
0
votes
1answer
87 views

Sed dynamic substitute, the unix way?

Got a bunch of files with domain qualified names in them, looking to replace them by their ip. Can I do that with one line of shell ( bash ) ? Typical input file ( nagiosconf ) : define host { ...
4
votes
4answers
895 views

sed - Print lines matched by a pattern range if one line matches a condition [duplicate]

I have a multi line log entry format that I need to process. The log looks something like this: --START-- Device=B Data=asdfasdf Lorem=Ipsum --END-- --START-- Device=A Data=asdfasdf Lorem=Ipsum ...
0
votes
1answer
56 views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA ...
0
votes
3answers
103 views

Pulling out a certain value from a string via regex

I've see a bunch of examples, but I just can't seem to make this work. Can grep output only specified groupings that match? for example seems like it should work, but I get either errors or no output ...
0
votes
2answers
138 views

Use multiple commands in sed to insert text after string with special characters

I am having a little trouble trying to do a search and replace using sed in a config file. I want to use multiple commands using the -e option to do the following. Step 1: find the first occurrence ...
3
votes
5answers
488 views

Find text between tab (\t) as a delimiter

I thought this will be simple, but can't find out how to do it. Scenario I have a single .csv file with id_user,text,id_group columns where each column is delimited by tabs such like: "123456789" ...
1
vote
2answers
44 views

Split file in two on line before pattern

This is an almost identical question to split file into two parts, at a pattern but instead of having the lines up to XYZ in file1 in the example file.txt: ABC EFG XYZ HIJ KNL I want to have the ...
0
votes
2answers
119 views

sed: Multiple -e or while loop?

I have a CSV file with tuples of values where I need to change occurrences of one into another in a different (large) file. Thus far, I have done a while read line [...] < foo.csv, essentially ...
0
votes
1answer
31 views

Print specific FULL column only by range

I have a file which have contents like this. Column1 Column2 Column3 Column4 USER1 25 Years xyz zyz 123 abc ...
2
votes
1answer
69 views

Sed: replace text keeping digit occurrence

I have some text like: Blablabla <b>[intlink id="</b>2204<b>" type="page"] Blalala I want replace it for remove the </b> and <b>, keeping the id="number". So it should ...
0
votes
1answer
20 views

sed - how to refer to the outer match from within a block?

For example: I have a piece of sed as follows: 36 sed $' 37 /^waitForVisible/ { 38 s/this/& and that/ 39 s/waitForVisible/expect/ 40 s/)$/).to be_visible\\\n/ 41 } with ...
0
votes
1answer
91 views

Need to capture part of file name into variable

I have bunch of CSV files named like so in a directory: s_m_u_supplemental_fields_account_9_4_2015_11_26_Error.csv s_m_u_supplemental_fields_account_9_4_2015_12_3_Error.csv ...
0
votes
1answer
47 views

Sed command with complex pattern and replacement

I have the following two strings saved as variables: str1='ds-cfg-global-aci: (targetcontrol="2.16.840.1.113730.3.4.2 || 2.16.840.1.113730.3.4.17 || 2.16.840.1.113730.3.4.19 || ...
1
vote
2answers
56 views

Remove last comma within a pattern

If I have the following text within a file (somefile.txt): CREATE TABLE "table_name" ( "id" int(11) unsigned NOT NULL, "some_field" varchar(10), ); CREATE TABLE "another_table" ( "id" ...
1
vote
1answer
44 views

Remove word after match

Consider the following line of text (taken from a MySQL insert): "description" varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', I want to return "description" varchar(255) NOT NULL ...
1
vote
2answers
92 views

Change time format in a file

I have output of a sar commands and the time is not POSIX: Linux 2.6.32-431.29.2.el6.x86_64 (test.server.com) 2015-08-01 _x86_64_ (32 CPU) 12:00:01 AM CPU %usr %nice %sys ...
0
votes
2answers
27 views

Delete multiple lines with text and curly braces

I have a multiple files that contains something like: this is a test1 { test 123 test 456 test 789 } this is a test2 { test 123 test 456 test 789 } this is a test3 { test 123 test 456 test 789 } ...
0
votes
2answers
31 views

Merge labels from lines with duplicate fields

I have a rather large text file(thousands of lines) in following format: 123.123 5 123.123 91 156.456 45 233.185 85 233.185 4 257.448 1 455.456 60 455.456 2 The first column are ...
0
votes
3answers
70 views

print last line of !! command

so I want to be able to print helloworld using the !! command. I tried creating a text file with the text helloworld on it. Then I say cat textFileName It prints helloworld. Then I say !! and it ...
0
votes
3answers
122 views

How to replace contents of each line depending on some formula?

I've been working with bash to get some data output to a multiline file with the data stored in this format for each row: text1 "text2" text3 integer1,integer2 A "space" separates the first four ...
0
votes
1answer
44 views

How do I correctly add line ends with sed? [closed]

I have several sed statements that at one points uses newlines in the output with \n (Actually they are sed's using $' with \\\n's`). However subsequent sed operations that wish to operate on the end ...
8
votes
8answers
815 views

Split text file into lines with fixed number of words

Related, but no satisfactory answers: How can I split a large text file into chunks of 500 words or so? I'm trying to take a text file (http://mattmahoney.net/dc/text8.zip) with > 10^7 words all in ...
2
votes
4answers
259 views

extract url between 2 strings in a file

I have a file in which each line is like this "372"^""^"2015-09-03 06:59:44.475"^"NEW"^"N/A"^""^0^"105592"^"https://example-url.com"^"example-domain < MEN'S ULTRA < UltraSeriesViewAll ...
2
votes
3answers
74 views

How to add “wrappers” around methods in source code based on a pattern, using sed, awk, grep and friends

How can I add wrappers to a file based on a pattern? For instance I have the following: ... find(css_policy_form_stage3).click with_ajax_wait expect(css_coverage_type_everquote).to ...
1
vote
1answer
38 views

How to query-replace after a given character in a string?

How to replace all / by . only in the sentence after the = ? For example, from this: /buttress_unit/buttress_top/buttress_i_ps_but_cio_m1_i_but_m1_tx_wrapper_m1_pref_fifo_array_29__stream_id_3_0 = ...
5
votes
8answers
640 views

awk or sed command to match regex at specific line, exit true if success, false otherwise

I need to determine if a file contains a certain regex at a certain line and to return true (exit 0) if found, and otherwise false. Maybe I'm overthinking this, but my attempts proved a tad unwieldy. ...
-1
votes
3answers
59 views

How to delete certain line from file?

I have a text file with line containing only comma. How can I delete this particular line? Consider following example: CREATE TABLE ENTERPRISE.TSDAILYACCTSUMMARY ( TSDAILYACCTID FOR COLUMN ...
-1
votes
1answer
79 views

How to add double quotes to a various strings in a same pattern in a file

I have a file like this CREATE TABLE ENTDTA.$$BAPWD ( PERSID NUMBER(10) DEFAULT 0 NOT NULL , "PASSWORD" CHAR(10) DEFAULT '' NOT NULL , UPDATE_IDENT NUMBER(7, 0) DEFAULT 0 NOT NULL ) ...
0
votes
1answer
102 views

Why is sed coming back with “unterminated `s' command”?

So I have a Bash script which looks like this: #!/bin/bash extentemplate=" exten => `$prevchannel`,n,Queue(`$prevchannelname`)\ exten => `$prevchannel`,n,Hangup()\ \ ;`$channelname`\ exten ...
-1
votes
1answer
30 views

Look for a particular pattern and do a swap on that line

I have a set of files containing VIEW_NAME FOR COLUMN DNAME , VIEW_OWNER FOR COLUMN DCREATOR , OBJECT_NAME FOR COLUMN ONAME , OBJECT_SCHEMA FOR COLUMN OSCHEMA So, ...
0
votes
1answer
76 views

Why won't my change to the sshd_config file persist? [duplicate]

I am writing a script to modify settings on my Ubuntu server. I have the following line in it: sudo sed 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config The problem ...
0
votes
1answer
41 views

replacing first link of a text “awk equivalent of sed command”

I wanted to replace the first line of a text with sed it should be like sed -i.bak "1 s/^.*$/"CompoundState\tMethod\tApproach\tS^2\tEnergy\tPath"/" awk.xls but I also need to run it on OSX but it ...
-1
votes
1answer
66 views

Using Sed or awk to put a string at the end of a line

I am trying to place a different sting at the end of each line using. The below works but not when the file is large. x=line # in the file. The data goes to the end with $. Let data=0 Let x=0 while ...
4
votes
2answers
330 views

How to change all strings in python file from snake_case to camelCase in sed

I've tried some sed patterns like this from commandlinefu sed -r "s/('[a-z]+)_([a-z])([a-z]+)/\1\U\2\L\3/" But somehow it's not working. For one thing they forgot the digits, which I can fix, but ...
6
votes
4answers
671 views

How to add a header and/or footer to a sed or awk stream?

I have a bunch of output going through sed and awk. How can I prefix the output with START and suffix the answer with END? For example, if I have All this code on all these lines and all these ...
1
vote
5answers
78 views

Making a *nicely* formatted list of number of files in directories - awk & sed probably

I have lots and lots of files in a series of directories, and would like a nicely formatted list of how many files are in each directory. The directories are ordered thus: Parent directories named ...
2
votes
1answer
48 views

Question about replacing character in text file

So I have some data that is parsed in this format seperated by colons: username:email@email.com:password:salt Sometimes the username/salt can contain a colon (:) in it. I want to replace the ...
0
votes
0answers
66 views

Sort Checkpoint Firewall log into easier output

I am trying to sort out this log: Aug 27 01:23:38 1.1.1.1/1.1.1.1/1.1.1.1 fw1-loggrabber[0000]: loc=12569|time=2015-08-27 ...
0
votes
1answer
57 views

Big XML - copy data from nth Occurrences to another file

<XML> <Employee> <firstname></firstname><lastname></lastname> </Employee> <Employee> ...
1
vote
5answers
197 views

lines to columns with awk

I have to following sample output: <HARDWARE> <NAME>WIN1</NAME> <OS>Windows 7</OS> <IP>1.2.3.4</IP> <DOMAIN>contoso.com</DOMAIN> ...
0
votes
1answer
313 views

SED - Find and replace with special characters (#, , % )

I'm aware that this is a really simple question, but I'm struggling to find a solution to this . I need to automatically find and replace in the /etc/aliases file the following section: # Person ...