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

learn more… | top users | synonyms

0
votes
1answer
97 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
1k 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
58 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 success,1234,["madhu",{'first',[{'last',18}]},"I0"...
0
votes
3answers
122 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
170 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
762 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
53 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
155 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
32 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
78 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
21 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
96 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
49 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.3.6.1.4.1.4203.1.10....
1
vote
2answers
62 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" int(...
1
vote
1answer
55 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
111 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
28 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
33 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
72 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
131 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
51 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
1k 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
478 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 (18)"^"...
2
votes
3answers
77 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
741 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
66 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
87 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
117 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
31 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
101 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
44 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
67 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
363 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
1k 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
88 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 A,...
2
votes
1answer
49 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
77 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 01:23:37|action=block|orig=192.168.1.1|i/f_dir=outbound|i/f_name=eth1-04|...
0
votes
1answer
65 views

Big XML - copy data from nth Occurrences to another file

<XML> <Employee> <firstname></firstname><lastname></lastname> </Employee> <Employee> <firstname></firstname><lastname></lastname>...
1
vote
5answers
223 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
385 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 ...
3
votes
6answers
197 views

Find a pattern and insert # at the beginning of 2 line before that and 1 line after that

I have a big file (more than 2000 lines). Where I have to insert a # at the beginning of 2 above lines and at the beginning of 1 below line after finding a pattern. Also insert # at the beginning of ...
1
vote
2answers
116 views

How to replace string in files except with a line begins with # [duplicate]

I've looked at some other questions related to using sed to replace strings, but I'm having trouble figuring out how to apply it to my particular need. In a case like the snippet below, I want to ...
4
votes
6answers
233 views

Changing matrices into single lines of data

I have multiple matrices in a .txt file and I need each matrix to be in a single line. For example, matrices.txt: 1 2 3 4 2 3 4 5 3 4 5 6 3 4 5 6 2 3 2 5 2 3 4 5 2 3 5 6 2 3 4 5 ... What I would ...
0
votes
5answers
74 views

Appending One File to the Second Until End of File

I have two files. The first is just a single number. This number is calculated and changes every time. The second file has a bunch of columns, and I do not know the number of rows (which can change). ...
1
vote
1answer
137 views

Is sed run as a different user?

I have a sed script that changes some content in /etc/shadow. The actual change isn't important, I will put it just as an example: root@device:~ sed -i 's/root:\(.*\):0:0/root:\1:10:0/' /etc/shadow ...
1
vote
1answer
216 views

sed command to delete variable number of lines

To delete the first 10 lines from a text file, the following command is used: sed -i -e "1,10d" filename what if I want to delete n number of lines, where n is a variable. i.e. I am using ...
1
vote
1answer
158 views

Script to remove certain span elements from an HTML file

I want to write a script that completely removes every instance of a particular span class from a given HTML file. For example, if my undesired span class is "foo" then running my script on the file ...
0
votes
2answers
132 views

sed in while read loop doesn't complete commands

I have a test file called testPage with the following text: || '''Title1''' || '''Title2''' || '''Title3''' || || Cell11 || Cell12 || Cell13 || || Cell21 || Cell22 || || Cell31 || Cell32 || || Cell41 ...
0
votes
1answer
98 views

How to replace \1\ with new line

I have a record like: "evSchema"\1\"UAT" "evSN"\1\"uadb" "evDirsep"\1\"/" "evRootPath"\1\"/work_area/APP_UAT/" "evSchema"\1\"RMS13" "evUser"\1\"STAGE" I want to replace \1\ with new line. I tried ...