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

learn more… | top users | synonyms

0
votes
1answer
32 views

replace inside a file with some specific structure

I have a file look like: login1.stampede(73)$ cat mc_input 800 ! n_pass 300 ! n_equil_pass 6 6 6 ! simulation cell dimension in x, y, and z 700 ! Tinit 100 ! Tmin 700 ! Tmax -10 ! Tinc Li -...
11
votes
4answers
37k views

How to use Sed to replace all characters before colon?

How do I replace the following string hd_ma_prod_customer_ro:*:123456789:john.doe with john.doe Basically I need to look for the last colon (:) and delete everything before and including it.
0
votes
1answer
33 views

How to catch everything after prefix phrase with SED?

How to catch everything after prefix phrase with sed? Like here I wished to catch active/idle: $ sudo hdparm -C /dev/sda /dev/sda: drive state is: active/idle $ sudo hdparm -C /dev/sda | sed "s/\...
2
votes
1answer
61 views

find and replace a string in a file without using temp file with SED

I have a text file called sample.text which looks like this Continent Lat/Lon: 46.07305 / -100.546 Country Lat/Lon: 38 / -98 City Lat/Lon:(37.3845) / (-122.0881) I want to process this text to get ...
2
votes
1answer
34 views

using Sed to find and replace a string inside a file [closed]

I have been trying to replace '{{date}}' with a current date stamp in OSX command line. I have been using the following: sed -i -e 's/{{date}}/`date`/g' mhp.xml Does anyone know why it ends up ...
0
votes
0answers
30 views

How to add time stamp(month_year) to the file after matching specific string?

I want to add time stamp inside the file only after matching specific string, time stamp format: 03_2016 file contains "$channel_name Policy" string, I want to replace this string with "$...
0
votes
1answer
44 views

Removing new line characters around patterns

I have a fasta file of millions of paired sequences, that looks like this: >7001289F:56:HKH3FBCXX:2:1101:1692:2074 1:N:0:CGATGT ...
1
vote
1answer
26 views

How to replace a word in a file by a word get by read function? [duplicate]

Situation: echo "tell me a word" read the_word How to replace all WordToReplace in a file by the_word? sed does not seems to appreciate: sed -i 's/WordToReplace/$the_word/g' thefile.sh
0
votes
2answers
63 views

How to get only certain fields from a given file?

I have list of employees in following format Name: Phone No: Email: Name: Address: Phone No: Email: Name: Country: Address: Phone No: Email: Name: Address: Name : Email: Address: All I want ...
3
votes
2answers
55 views

sed pattern and multiline substitution

I need to parse a text file and replace a certain portion of it. I believe sed is the way to do it but not sure how to handle multiple lines with it The pattern I am looking is set cells { \ cell1 ...
1
vote
1answer
36 views

Remove lines that contain file path using sed

I have a list of lines in a file that look like this: 6642a51e0ed5e6f89e5e4090b9aa0fb3 /home/device/eth0/uid d66d1417251a9a151176c34acf046878 /home/device/eth0/uid64 ...
1
vote
2answers
105 views

Find files containing a set of words

I'm using grep to find files within a directory, containing a set of words. But grep search lines containing these words, what I want is grep to show me the files or file containing all those words ...
-1
votes
1answer
45 views

Understanding operators using sed

Trying to understand and break down this command. echo -e '1234\n4567' | sed 's/^\(..\)\(..\)$/\1:\2/' Being a novice with shell and sed I'm at a loss where to start in breaking down various ...
1
vote
1answer
57 views

Extract random sample of N lines based on pattern

I have a file formatted like this: train/t/temple/east_asia/00000025.jpg 94 train/t/temple/east_asia/00000865.jpg 94 ... train/s/swamp/00000560.jpg 92 train/s/swamp/00000935.jpg 92 .... train/m/...
9
votes
4answers
34k views

How to add a carriage return before every newline?

I have a file that only uses \n for new lines, but I need it to have \r\n for each new line. How can I do this? For example, I solved it in Vim using :%s/\n/\r\n/g, but I would like to use a script ...
2
votes
2answers
26 views

How to append a string to the first column of a matrix file?

I have a matrix file as follows. The first column is a name list. I want to add _i1 to the end of each name. A1A A1B A1C A1D A1E TR6764_c0_g2 0.00 0.02 0.00 0.00 0.00 ...
0
votes
1answer
34 views

Remove tab, new line, carriage return until encountered char

I have a CSV file that has record separator of ,\n. One of the columns, has the possibility of containing tabs and new lines, which I wish to remove. How do I remove these chars (\t\n\r) using sed and/...
2
votes
0answers
55 views

Awk /sed extract information when a pattern match from a paragraph

I want to search a pattern "FROM" in paragraph that begins with CREATE VIEW and ends with ";" and save the result in a csv file. for example if I have the following file : CREATE VIEW view1 AS ...
2
votes
2answers
373 views

How do I add an if statement (regarding punctuation in a word) to this bash script

I have this bash script #!/bin/bash cat $@ | while read line do for word in $line do echo $word | circling-the-square # here's where i need to add the if statement: #...
3
votes
1answer
42 views

Get contents of a file from first instance to last instance of some arbitrary string

How can I view in less from the first instance of some arbitrary string "foo" to the last instance? This arbitrary string will be on most every line of the log. I don't want to do grep "foo" bar.log |...
1
vote
1answer
38 views

Sed delete line if nth character is not specific character

I have a csv file, and I want to delete lines if their 12th character is not ;. So, for example, my file looks like this: 2266308;A;B;dfsgsfdg 2266309;A;BJHSADFK;gfsdg 2266310;A;B;dfg and I ...
0
votes
3answers
39 views

remove sequential lines that begins with the same pattern using awk or sed

I want to remove the sequential lines that begins with the same pattern "CREATE CURRENT" using sed or awk for example if have the folowwing file: CREATE CURRENT = 'aaaa' ; CREATE CURRENT = 'bbbb' ; ...
0
votes
2answers
50 views

insert complex line before or after complex line

i have file with complex text print("ERROR: passwords don't match") password = hash_func(password.encode("UTF-8")).hexdigest() i need to insert this text between them with open('/etc/openvpn/...
1
vote
3answers
45 views

Count occurance of number and delete line of matches value

Could I get some help please with my problem? I have a file that looks like this (comma separated): A,250,13,820,0,80,201 B,0,0,0,0,3,0 C,0,2,1,0,0,0 D,0,1,105,0,0,10 I would like to ...
0
votes
2answers
54 views

using sed to modify all files in a directory and name the outputs accordingly

I want the sed command to work on all files in a directory and output the result into a new file. If f is val1.txt, the name of the output file should be val1_ended.txt -this is what I am trying to do ...
0
votes
2answers
35 views

sed to change dns log string format

I want to use sed to change the following text: (3)www(5)first(3)nth(6)domain(3)com(0) to: www.first.nth.domain.com Can each group between the parenthesis separators be captured and then ...
1
vote
3answers
73 views

How to do following formatting using sed or awk or bash script on linux

Suppose, I have two files: file1 having below contents. message_aaa.wav test 1 of 1 test Label : aaa test Sentence : test aaa test String: test message Interpretation ...
1
vote
2answers
38 views

Sed from line 6 on from all txt files and being able to output all the results in a single file

I need to sed from all *.txt files from line 6 until the end All the results should be in a new single file with the name of each file preceding the results Example: Having different txt files the ...
0
votes
2answers
52 views

using awk to unzip files in directory

I have some zip files in directory when I need to unzip each in specific dir I used ls | awk '{ print "unzip " $1 " -d " $1} ' unzip p21286665_121020_Linux-x86-64.zip -d p21286665_121020_Linux-x86-...
4
votes
3answers
144 views

String replacement using a dictionary

What is a good way to do string replacements in a file using a dictionary with a lot of substituend-substituent pairs? And by a lot, I actually mean about 20 – not much, but many enough so that I want ...
19
votes
3answers
4k views

Make sed ask for confirmation before each replacement?

Is there a way to make sed ask me for confirmation before each replace? Something similar to 'c' when using replace inside vim. Does sed do this at all?
-1
votes
1answer
29 views

Remove pattern from a line in file with Grep/sed/awk combo, pattern is another column

I have two columns (or could separate as two files) in a huge file and i need to remove the duplicate city name in the state/area column. los angeles los angeles ca, usa, west new york ...
3
votes
3answers
46 views

Strings - Extract File Version Recursive

I have been using strings to extract and compare file versions between directories. I don't seem to be able to do this recursively. The method I have been using per file is: strings -e l ...
0
votes
3answers
77 views

How can I escape special characters in a sed “sub-command”?

I'm using xmllint --shell on a large XML file, and using the write command to write out an XML snippet to be used in testing. The snippet that gets written out needs a couple of lines from the ...
1
vote
3answers
81 views

Make multiple edits with a single call to sed

I'm trying to use sed to edit a config file. There are a few lines I'd like to change. I know that under Linux sed -i allows for in place edits but it requires you save to a backup file. However I ...
0
votes
2answers
35 views

shell scripts when exceeding 100 seconds to send an email

When executing show engine innodb status on mysql, there are lines like ---TRANSACTION 17610C9A, ACTIVE 504 sec starting index read. I need a script to monitor for when the number of seconds after ...
10
votes
3answers
13k views

How to sed only that lines that contains given string?

INPUT: Select ASDF 325 sdfg sdflk lk Select TRG 46sdg rasdftz fsgs 45 Select ASDF 6ffg sdfg 4456 sdrg OUTPUT: Select ASDF 325 XXXX sdflk lk Select TRG 46sdg rasdftz fsgs 45 Select ASDF 6ffg XXXX ...
4
votes
3answers
1k views

Append line to many files

I want to add some text to over 200,000 files I am trying this find . -name *.txt -print | xargs -I % echo "hello world" >> % But nothing is happening. When i run find . -name *.txt it work ...
1
vote
1answer
55 views

Sed command usage without defining variables in shell script

I have two variables source_repo="fdl_ppe_01_04_repos_svc" target_repo="fdl_ppe_01_10_repos_svc" and I currently do a substitution within an XML file to replace all instances of $source_repo with $...
4
votes
1answer
91 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
0
votes
2answers
38 views

Using sed to pad-right a number in a CSV

I have thousands of lines that look like this: e0f186cf-c34d-42e9-b8a9-9b9cf1f304e7,TotalNumberOfHandledConnectionsOrSessions,TotalNumbe1211008586,1457343000,179.00 The column before last is a ...
3
votes
5answers
79 views

How to extract data from a file and construct a filename from one of the values

I'm trying to pull two values from a configuration file and write them to a new file. The hard part is that I want the name of the new file to be determined by one of the values in the input file. ...
0
votes
1answer
36 views

find lines that don't end with 'rpms' with sed

I would like to find lines that do not end with 'rpms' with sed in Linux. I have tried below: sed -ne '/?!(rpms$)/p' But unfortunately, it is not correct.
3
votes
6answers
171 views

Add quotes and new delimiter around space delimited words

I have the following string y10_zcis y10_nom y10_infl y20_zcis y20_infl y30_zcis I would like to transform this to "y10_zcis", "y10_nom", "y10_infl", "y20_zcis", "y20_infl", "y30_zcis" I ...
1
vote
6answers
12k views

compare two files get identical list

file1.txt (50 lines) TERYUFV00000010753 TERYUFV00000009526 file2.txt (500 lines) TERYUFV00000009526 refids_739_known_8/10_target TERYUFV00000018907 refids_12023_known_21/22_target ...
1
vote
1answer
247 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
-1
votes
1answer
44 views

In a text file how can I sed multiple portions of text bordered by specific text patterns of text on Unix?

I use sed -n START_LINE,FINISH_LINEp filename > newfile to extract a specified range of text from a text file, e.g. sed -n 45,50p datafile > newfile. How can I use this to extract multiple ...
1
vote
3answers
85 views

How to add a different prefix to every line in a grep output?

I currently have this code: cat /proc/cpuinfo | grep "MHz" | cut -d ':' -f2 | sed 's/.*/Core NUM&Mhz/' Which outputs the following (for 8 cores): Core NUM 1941.054Mhz Core NUM 1949.820Mhz Core ...
1
vote
2answers
58 views

Use sed to replace a text and output to a new line and also print it

I need to change replace a text in a file and output the whole text file with the changed text and also print it to the screen. This is what I got: sed 's/123/456/g' number > number123 This ...
1
vote
1answer
42 views

Multiline(in one paragraph) pattern replace use awk or sed

$cat test.txt blablabla ```{r} blabla ``` blablabla blablabla blablabla ```{r} blablabla blablabla imname <- "FIGNAME1" saveflag <- savepdf(imname) ``` ```{r} blablabla blablabla imname <...