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

learn more… | top users | synonyms

3
votes
2answers
289 views

Find the line number which contains the pattern with custom delimiter

As in example I'm trying to get line numbers which contains the pattern. My pattern contains slashes so I wanted to add custom delimiter. This simple one works: sed -n '/file/=' temp.txt Using ...
0
votes
1answer
40 views

How to find & replace pattern WITHIN specific pattern using sed

IT seems that 'sed' and I will never be friends... How can I find and replace a pattern within a range (within another pattern)? In words: Find: AllowOverride None within the following range and ...
1
vote
4answers
158 views

How to recognize which ASCII character in hex is this?

We have a textfile that we want to clear from "bad" characters. If we open it with vim (with ":set number"): 57000044 zo¥<9a>¥ge¥o¥graph¥i¥cal¥ly 39999999 pariá¹<83>Å<9b>a The ...
7
votes
4answers
5k views

How to embed a shell command into a sed expression?

I have a text file with the following format: keyword value keyword value ... Where keyword is a single word and value is everything else until the end of line. I want to read the file from a shell ...
7
votes
3answers
2k views

Cleanly swap all occurences of two strings using sed

Suppose I have a file that contains multiple occurrences of both StringA and StringB. I want to replace all occurrences of StringA with StringB, and (simultaneously) all occurrences of StringB with ...
0
votes
2answers
70 views

Find and replace values with counters [closed]

Sorry my earlier question was bit confusing... I have a file that has values like: location 100 SlotNumber ..some lines inbetween location 150 SlotNumber ..some lines inbetween location 160 ...
1
vote
2answers
75 views

sed - doesn't append new line EOF and replaces letter not defined

I am experiencing a strange behavior using a sed command (got to be sed, no awk in this case) and got two questions for you, hoping someone got the skills to explain me what I am doing wrong. I want ...
0
votes
0answers
14 views

How to change the string /vol/oracdump/ with /vol/nfs_ssdb/vmcoredump using sed ? Please help me [duplicate]

How to change the string /vol/oracdump/ with /vol/nfs_ssdb/vmcoredump using sed ? Highly appreciated if I get your response.
2
votes
4answers
101 views

How to highlight given string in given place?

How can we modify this: <a href="http://foo.bar1">asfdlksafbar1qsasadf</a><br> <a href="http://foo.bar2">svasfbar2saldkfj</a><br> <a ...
0
votes
1answer
56 views

Error while passing variables for keyword match using sed

I am a beginner in scripting. I am writing a bash script for text processing where this command is giving me error: sed -e "/\<$7\>/ /\<$5\>/$6/" < "$2/$1" > "file.tmp" This is ...
1
vote
1answer
42 views

Trouble with Sed Syntax

I'm modifying raw PCL/PS files (mixed) and for some reason I can't get my Sed syntax right for the true beginning that I want it to grab. Here's a sample output from the strings command: *c50B *c0P ...
0
votes
2answers
38 views

Select lines and format

Is there a way to format the following output so that only lines 1 and the respective lines that state the "rule" name print out? Depending on the configuation, the "rule" line could vary. It could be ...
1
vote
1answer
59 views

Pattern matching and removal of that pattern using sed

I have 2 files with the following names: File 1: RvA_X-IRB-bil-CA101-0+010000-20150327212332-055582-P File 2: RvA_X-IRB-bil-CA101-1+020000-20150327212332-055582-P I am using this command to match ...
1
vote
2answers
51 views

SED replace after ignoring

There are many lines in a text file and I would like to change the value true to false using a one line script. bash-3.2$ grep online test.txt # online = false --> ONE SHOT import (delete all ...
0
votes
1answer
72 views

Modify part of line if keyword is found using sed? [duplicate]

I want to modify a line if a specific keyword is found in a line. CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME In above line, if 'PORT_NUM' is present then ...
4
votes
3answers
222 views

Get last part of string after hyphen

Is there a simple command line to extract the last part of a string separated by hyphens? E.g., I want to extract 123 from foo-bar-123.
5
votes
4answers
301 views

Want to substitute only first occurence with sed

Original file claudio antonio claudio michele I want to change only the first occurrence of "claudio" with "claudia" so the file result claudia antonio claudio michele I have tried sed -e ...
1
vote
5answers
71 views

keep out line break

I have some files with this structure: 2015-03-25 17:08:17 sysUpTimeInstance 93474;^M 1.ValueforState=2500 I want to replace the line break, and leave the third line with the second line, I mean, ...
0
votes
2answers
115 views

How to delete specific lines within a certain area?

I want to delete some specific lines in the YAML front matter: --- Author: aaaa Title: bbbb Time: cccc Place: dddd ... Lets say I wanted to delete only the lines in the front matter that contained ...
1
vote
2answers
57 views

Parsing C Style Multiline Comment

I want to filter non-commented javascript with sed and output the line number Here is the example: /*! * jQuery UI 1.8.17 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Dual ...
8
votes
5answers
5k views

How to remove multiple blank lines from a file?

I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
2
votes
1answer
53 views

How to avoid sed -i to destroy symlink?

Why does sed -i executed on symlink destroys that link and replaces it with destination file? How to avoid this? eg. $ ls -l pet* -rw-rw-r-- 1 madneon madneon 4 mar 23 16:46 pet lrwxrwxrwx 1 madneon ...
1
vote
2answers
63 views

How to list only the last line of each directory?

I learned thanks to you, how to display only the last line of a listing,e.g. ls -ltr | sed '$!d' Now I thought, how to combine it with the find command, in order to repeat this onto each directory ...
0
votes
3answers
44 views

How to display only the last line of a listing ?

Supposed I make a listing and sort the files by its temporal attribute: ls -ltr -rwxrwxrwx 1 bla bla 4096 Feb 01 20:10 foo1 -rwxrwxrwx 1 bla bla 4096 Feb 01 20:12 foo2 . . . -rwxrwxrwx 1 bla bla ...
0
votes
0answers
28 views

Would this command delete only the lines containing specific words within a delimited area? [duplicate]

Please see my previous question here. No one seems to be following up on it, so I have tried to have a go myself: sed '1 { /^---/ { :a N; /\n---/! ba; /^Title: \|^Place: /d} }' filename Would this ...
2
votes
2answers
67 views

Live replacement, while viewing log using LESS

It's very convenient to monitor logs using less command - you see what is going with your system as it happening. The bad thing is that my logs are optimized for grep tool: each atomic action is ...
1
vote
1answer
53 views

Write text on last line of document [duplicate]

If I have this document aaa bbb ccc And I want to add " ddd" on the last line. My document should look like this: aaa bbb ccc ddd How can I do this? If I prefer awk or sed but ...
1
vote
2answers
108 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
0
votes
1answer
41 views

Sed a plist file gives a iilegal byte sequence

With a Unix Mac 10.9.5, French CA version I've read a lot of tips but if the error is gone, the plist is corrupted. the locale command gives: LANG="fr_CA" LC_COLLATE="fr_CA" LC_CTYPE="fr_CA.UTF-8" ...
9
votes
2answers
17k views

How to replace a string with a string containing slash with sed?

i am looking for a way to replace a string in a file with a string that contains a slash by using sed. connect="192.168.100.61/foo" srcText="foo.bar=XPLACEHOLDERX" echo $srcText | sed ...
2
votes
1answer
67 views

sed match pattern and act on x lines after

I'm trying to find a way to comment out a block (multiple lines) in a configuration file. I'd like to match the first line but also act on each line after that. sed '/\/Some\/Foo\/Bar\/String/' ...
10
votes
3answers
6k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 ...
1
vote
2answers
75 views

Sed move line from n° 40 to 39 position [duplicate]

I have a text file,of 100 lines,i need to move line 40 to line 39(refer to position) How to do this with sed? I tried sed '40 m 39' file and sed '40,39m' file but give me error. Thanks
4
votes
6answers
19k views

Extract a part of one line from a file with sed

I want to read one part of one line from a file. For example: POP3_SERVER_NAME = localhost I want to return only localhost, using sed. This text is on the third line. I do this to extract the ...
1
vote
4answers
202 views

SED command to format text file

I need to create a SED command to modify an input file with some conditions explained below. I have an input file something like below. List item Rad# ; ID_KEY ; UNIT_ID 1 ; 30000000004 ; 8417920 ...
15
votes
2answers
64k views

Return only the portion of a line after a matching pattern

So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a ...
0
votes
2answers
231 views

sed command to replace a string from one file with entire contents of another file [duplicate]

I want to write a sed (or awk) command to replace a string from one file with the entire contents of another file. Note that second file from which I want to get the content has more than one line. I ...
3
votes
1answer
56 views

sed - perform multiple substitutions on a line found by pattern search?

I have a file which contains a like like this: name=MOD0 and a lot of extra lines which I'm not interested in. I need to transform this line into this: [MOD0] and drop all other lines from the ...
0
votes
2answers
54 views

Replace a range of text with special characters using sed

I am trying to replace a range of text with sed containing special characters. I have the following output: "Users" "/Users/Users" SERVER1 "Roaming Profiles" "/Roaming Profiles/Roaming Profiles" ...
3
votes
1answer
128 views

how to change the replacement of word in the specific line using sed command?

I have to change a word in the 4th line so I used this command: sed -i '4 s/previous_word/new_word/' filename and it worked perfectly. But if I save the line number in a variable and try the same ...
2
votes
2answers
71 views

Using the sed command in Unix

how do you take one word from a file and change it to an absolute path? Basically I need to take one word from a unix file and change it to a absolute directory path in that file. The file name is ...
1
vote
3answers
217 views

how to delete line from the XML file

how to delete only the line from xml file ( with sed/awk or perl one liner line ) that start with: <units> and ended with </Networks> as the follwoing <units><unit ip= ...
2
votes
2answers
338 views

Strip #xxx comments except when they occur inside quotes in sed

How to solve the following problem? Input hai this is "#test" #this is comment Question: How to remove only the comment in shell script. Expected output: hai this is "#test"
2
votes
2answers
86 views

SED on Mac OS X

I'm using a MacBook Pro and I want to find and replace a given word with another with sed command, but it makes no changes. What is the problem? sed 's/\<cat\>/dog/g' tt.txt
2
votes
1answer
86 views

Expanding paths in Bash variables into sed expressions

I would like to ask what's wrong with this line? sed -i "/$PWD/a\ Hello World" historia.txt when I had it in this '' except for "" it was working, of course without expanded variable.
6
votes
4answers
11k views

Use sed to find whole word and replace

I have the following block of text in a file: test3.legacy test4.legacy test3 test3.kami I only want to search for test3 as a whole and replace it with nothing. Unfortunately, all my attempts have ...
1
vote
2answers
76 views

Swap line containing pattern with next line

I currently have the following code which nicely outputs some information about the wireless networks around me: sudo iw wlan0 scan | sed -nr '/SSID: |signal: |primary channel: /p' | sed ...
0
votes
1answer
60 views

effect of [0-9]* in a regular expression

What is the function of [0-9]* in the following statement, which will write all lines that start with an even number, followed by a space, to the file even: sed -n 's/^[0-9]*[02468] /&/w even' ...
1
vote
1answer
84 views

Problem with sed substition in multi-word regex

Take this simple example: echo "20150310 21:12:01.846338::: <?xml version="1.0"?><Haystack><Event " \ | sed 's/^\(.\{24\}\)::: \(<?xml.*><Haystack\|Foo\)>\(.*\)/\2 ...
4
votes
2answers
153 views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i ...