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

learn more… | top users | synonyms

1
vote
1answer
37 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 ...
1
vote
3answers
43 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
49 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
37 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
48 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 ...
4
votes
3answers
117 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
28 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
41 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
62 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
73 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
31 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
54 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 ...
3
votes
1answer
89 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
33 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
75 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
32 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
170 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
228 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
72 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
54 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
41 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 ...
1
vote
3answers
44 views

replace a string 6 line after matching string

I want to change notification_interval from 15 to 2 for block File_Check only. I tried changing line 6th after matching File_Check line with: sed -e '6 /File_Check/ s/15/2/g' file.txt but it did ...
1
vote
2answers
124 views

Append line to a block of text incrementing the value from previous line

I have a text file name class.txt with follow contents. [serverClass:MAIL] whitelist.0=LATE whitelist.1=ONTIME [serverClass:LETTER] whitelist.0=FIRST whitelist.1=SECOND whitelist.2=THIRD ...
2
votes
3answers
2k views

AIX's sed - in place editing

Is there any undocumented flag in AIX's sed implementation that allows in-place editing? The man page shows no flag for this operation, which is one of the most useful ones in other UNIX flavours.
3
votes
4answers
90 views

How to delete a specific number in file?

I have a file: 1 2 5 6 8 0 0 0 0 1 2 5 6 8 0 0 0 0 1 2 5 6 8 0 0 0 0 1 2 5 6 8 0 0 0 0 I want delete all zeros: 1 2 5 6 8 1 2 5 6 8 1 2 5 6 8 1 2 5 6 8 I tried tr -d [:0:]. Unfortunately, it ...
0
votes
1answer
31 views

How to replace word in specific column if it does not match an expression?

I have the following file: chr1 157784 157887 U6 0 - chr1 564813 564881 miRNA 0 + chr1 564879 564950 tRNA 0 - chr1 564952 565019 tRNA 0 + chr1 566062 566129 ...
11
votes
4answers
25k views

How to extract logs between two time stamps

I want to extract all logs between two timestamps. Some lines may not have the timestamp, but I want those lines also. In short, I want every line that falls under two time stamps. My log structure ...
95
votes
3answers
141k views

What characters do I need to escape when using sed in a sh script?

Take the following script: #!/bin/sh sed 's/(127\.0\.1\.1)\s/\1/' [some file] If I try to run this in sh (dash here), it'll fail because of the parentheses, which need to be escaped. But I don't ...
0
votes
3answers
43 views

Extract Strings from Web Log file

Given a file containing web access logs for a YouTube video, every line is a hit and is in the format. 62.172.72.131 - - [02/Jan/2003:02:06:41 -0700] "GET /random/html/riaa_hacked/ HTTP/1.0" 200 ...
6
votes
3answers
233 views

How can I display 3 lines of text at a time onto 1 line?

I have a log file that displays data 3 lines at a time. Like this: 1 data 2 data 3 data 1 data 2 data 3 data 1 data 2 data 3 data I'd like to take each 3 lines and ...
3
votes
2answers
123 views

How to extract several data from a file and store it in a csv file?

I have a file in the following format : 19-08-02 Name appel ok hope local merge (mk) juin nov sept ...
3
votes
2answers
42 views

Using literal empty curly braces {} inside sed command from find -exec

I'm wondering if it is possible to include empty curly braces {} inside a sed replacement called from a find -exec. An example: find "$dir" -type f -name "*" -exec sed -i s/hello{}a/hello{}b/g '{}' ...
0
votes
3answers
45 views

Increase integer in string by 1 for each line

with for example sed, awk or python. there will be 548 lines in the original txt file from this: http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3 ...
19
votes
4answers
40k views

Delete last line from the file

I use sed to quickly delete lines with specific position as sed '1d' sed '5d' But, what if I want to delete the last line of the file and I don't know the count of lines (I know I can get that ...
0
votes
1answer
31 views

pattern regex for apache rewrite

I have a bunch of URLs counting to thousands i need to redirect and there are thre main patterns in URL first pattern There is a dash - starting the title url and want to remove that dash e..g ...
3
votes
4answers
69 views

Bash converting path names for sed so they escape

I'm having a problem with a script. It is meant to change a value in a file called %DIR% so that it becomes a path name. The problem is the slashes in the directory name upset sed, so I get weird ...
0
votes
3answers
54 views

sed backreference: get each line and append it to end of line

I have a file with following content: $ cat -n w 1 Smith John 12345 jsmith 2 Jones Robert 23456 rjones 3 Green Ralph 34567 rgreen 4 Brown Fred 45678 ...
1
vote
1answer
29 views

Busybox ASH inside initrd has a problem when piping tee to sed

I'm trying to log the early boot output from the init script. This is what is working: mkdir -p /run/log && \ mkdir -p /tmp && \ mkfifo /tmp/stage-1-init.log.fifo1 && \ mkfifo ...
0
votes
3answers
71 views

Count all lines between a delimiter

I want to count the number of addresses attached to each device in the below example. Preferably using awk or sed. /dev/1 addr1 sometext sometext sometext addr2 sometext sometext sometext addr3 ...
1
vote
2answers
42 views

sed + remove char after specific word

I want to delete the last "." only if "." exist after "usa" word my sed command only removed the last "." , but what need to add to the sed syntax (a rule) in order to remove the "." only after ...
1
vote
1answer
52 views

why this simple sed script didn't work “nginx -V 2>&1 | sed -r 's/--/\\n/g'”

the output of "nginx -V" is a mess. nginx version: nginx/1.9.3 (Ubuntu) built with OpenSSL 1.0.2d 9 Jul 2015 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE ...