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

learn more… | top users | synonyms

-1
votes
1answer
10 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
18 views

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

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
16 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 ...
0
votes
1answer
27 views

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

I am trying to place a specific sting at the end of a line using sed. In my file, 64 position is where I am trying to put the string. I've used echo since I've struggle in how to insert a data value ...
4
votes
2answers
202 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
161 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
50 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
36 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
19 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
30 views

Big XML - copy data from nth Occurrences to another file

<XML> <Employee> <firstname></firstname><lastname></lastname> </Employee> <Employee> ...
1
vote
5answers
111 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
53 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
3answers
47 views

Find a pattern and insert # at the beginning of 2 line befoe 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
32 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
198 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
68 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
29 views

Is sed run as a different user?

I have a sed script that change some content in /etc/shadow. The actual change isn't important, will put it just as an example: root@device:~ sed -i 's/root:\(.*\):0:0/root:\1:10:0/' /etc/shadow sed: ...
0
votes
1answer
22 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 ...
0
votes
1answer
22 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 ...
-1
votes
1answer
28 views

replace numbers with zero while we have the lines number [closed]

I am trying to write a bash script (containing awk or sed ) to replace some numbers with zero. for example : replace line 3 second and third number, and line 4 first and third number and line 5 first ...
0
votes
2answers
55 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
82 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 ...
0
votes
1answer
33 views

Repeatedly extract every second and third line of a file with 3-line data blocks

I have a file where I have data in 3-line sets. I want the 2nd and 3rd line from each set. How do I get that? For an example from: [set no][no of line in set] 11 12 13 21 22 23 31 32 33 I want: ...
0
votes
1answer
4 views

Find line within file matching pattern and make a substitution

I'm trying to simplify my life here but I'm stuck. I have a file containing multiple lines. Each line has a user and a number. I'd like to know a bash one-liner to search for a user and change the ...
-1
votes
1answer
34 views

sed: regular expression,how to substitute?

I have those line on a text file 36) SIGCANCEL 37) SIGLOST 38) SIGXRES 39) SIGJVM1 40) SIGJVM2 41) SIGRTMIN 42) SIGRTMIN+1 43) SIGRTMIN+2 44) SIGRTMIN+3 45) SIGRTMAX-3 46) SIGRTMAX-2 47) SIGRTMAX-1 ...
4
votes
2answers
339 views

How to change all lines consisting of one “0” character to something else?

I have a file with lines similar to the below: 0 0.1 0.0002 0 0.30 I want to replace the lines with a single 0 to something else like 0.0001. For the lines with a decimal and digits after, I don't ...
2
votes
3answers
61 views

remove lines that contain an specific text in a file

I have a file with a list of emails in it and each line has an email in it. I want to remove lines that contain example.com or test.com. I tried this: sed -i 's/example\.com//ig' file.txt But it ...
0
votes
2answers
17 views

Match a word with optional delimiters with sed, grep and PCRE

How do I match a word with optional delimiters? Say I have a file named file a b "a" "a c and I want to match only quoted or unquoted a (I don't want to match "a). I'd like to do such match with ...
-2
votes
2answers
98 views

Grouping input using awk,sed,grep

I have an input file as below: 1001 Ivanov I.I: chess 2021 Petrov P.P: chess, football 3352 Sidorov S.S: 1000 Putin V.V: judo 8773 Schwarzenegger A: judo, chess, football I expect ...
2
votes
2answers
66 views

Extract multiple instances of text between two words inclusive of starting word but exclusive of ending word

A PDB file contains numerous paragraphs of conformations of a protein. Each conformation starts with the keyword ATOM and ends with keyword END. I am trying to read the file in bash such that I ...
2
votes
1answer
26 views

How to combine posix character classes of a regex?

I need to combine different character classes in a regular expresion used by sed. I need to match [:word:] and the minus symbol -. How does that look like? All my attempty failed at trying or ...
1
vote
5answers
52 views

How to extract string between two characters with sed [duplicate]

I need some help with sed. I have tried to look for information to do this but I couldn't find any specific and people hardly provide an explanation of the provided solution so this makes difficult to ...
1
vote
1answer
44 views

How to use sed to replace keys in a file using a regex?

I would like to modify a file to replace keys, suppose these keys are in the file as: 42NM 52NM 23NO XNNM I would like to replace anything with NM, with the word "Okay". 1 #!bin/bash/ 2 3 if [ ...
0
votes
1answer
28 views

echo or sed out of a ks-file to generate a mysql_secure script

i will create a KS File (Kickstart for automated OS installation). i install mariadb with the ks file. But it seems a problem to execute the mysql_secure script. My idea is to generate a script in ...
2
votes
4answers
56 views

Join pattern line and consecutive non-empty lines, separated by commas and enclosed in ()

I have a file that has click css_add_violation_false click css_add_claim_false and select css_driver1_birth_date_month birth_date_month select css_driver1_birth_date_day birth_date_day How ...
4
votes
2answers
92 views

POSIX behavior of sed's ^ and $ regex anchors with multiline pattern spaces

What is the POSIX behavior of the sed ^ and $ anchors when used at the beginning and end of a regex if the pattern space contains embedded newlines, like after you use the N command? Should they ...
3
votes
4answers
58 views

sed - how to remove all lines that do not match

I have a html file. I want to remove all lines that do not start with <tr>. I tried: cat my_file | sed $' s/^[^tr].*// ' | sed '/^$/d' but it deleted all the lines.
0
votes
2answers
35 views

AWK, SED or GREP for extracting data from HTML file

Can anyone tell me which is best to use to extract the following data from a html file which was received with curl . <script>document.getElementById("test-summary").innerHTML = ...
3
votes
2answers
136 views

sed delete lines httpd.conf

I have a httpd config file from which I would like to delete the a whole block: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination ...
10
votes
6answers
456 views

Remove lines from a file depending on lines found in another file

File file1.txt contains lines like: /api/purchase/<hash>/index.html For example: /api/purchase/12ab09f46/index.html File file2.csv contains lines like: <hash>,timestamp,ip_address ...
-1
votes
2answers
21 views

How could I use sed to convert a js file with storedVars to a ruby file with methods?

I have lines like: storedVars["css_delete_driver"] = "css=.driver:nth-child(2) *[data-method=delete]"; storedVars["css_delete_driver2_mobile"] = "css=a.remove-driver"; and I want to create a file ...
6
votes
3answers
284 views

Print random lines respecting the order of the source file

I have a large text file (~500K lines) with short sentences (couple of words long). Additionally, there is some XML markup in most of the lines. Finally, the text file has been sorted before the ...
0
votes
2answers
31 views

sed command to append different text at multiple occurrence of string

I want to use sed command to append text at multiple occurrence of string. For Ex: Hello world types="program" Mario types="Game" Hello world types="program" Mario types="Game" So at first ...
0
votes
1answer
46 views

Replace command in Bash script from another script

I'm trying to setup a script that will fetch changes from github where a script has a command that's not executable in Mac OS X. What I'm aiming for is to use sed etc to replace the command within ...
0
votes
3answers
53 views

Insert blank line in UNIX after different number of lines

Suppose I have a file abc.csv with below data: abc def geh ijk lmn opq rst Now, I want to insert blank lines after line2 and line 6. Please suggest which command shall I use.
0
votes
2answers
22 views

Prevent sed from printing empty stuff

sed -e 's/\([A-Za-z]*\)\( \)\([A-Za-z]*\)\(:\?\)\([A-Za-z]*\)\?\( \)\?\(.*\)\?/[\1][\2][\3][\4][\5][\6][\7]/' will decorate class VoxelbuilderAdda:public VoxelBuilder So it looks like [class][ ...
1
vote
3answers
184 views

How to add an attribute in a tag in XML file by command-line?

I am trying to add field at the end of tag using sed script. Suppose I have a tag in XML file: <book name="Sed tutorial" price="250"/> Now I want to add field as Book_Width="A" after end of ...
1
vote
1answer
44 views

Replace LF with CRLF at the beginning of a file

I am writing a script that iterates through all the files and replaces line feeds at the beginning of each file. For a file like this, \n \n A line \r\n Another line \r\n \r \f \n \n Few more lines ...
1
vote
2answers
41 views

join two file based on column when there is no one by one corespondness in bash script (awk, grep , sed)

file1.txt 112|9305|/inst.exe 112|9305|/lkj.exe 112|9305|/dje.jar 112|9305|/ind.pdf 112|9306|/ma.exe 112|9306|/ngg.pdf 112|9307|/jhhh.dat 112|9312|/ee.dat 112|9312|/qwq.dll file2.txt ...
1
vote
5answers
41 views

How to use awk or sed to convert rows to columns

I need to transpose a file. Input file: 1/1/1111 1 2 3 4 2/2/2222 5 6 7 8 Output: 1/1/1111 1 2 3 4 2/2/2222 5 6 7 8