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

learn more… | top users | synonyms

3
votes
3answers
2k views

Delete XML node containing certain element

I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed: <Placemark> ...
0
votes
1answer
193 views

replacing text and deleting text using awk in file using

I have a script and I want to do some replace and delete operations on it. I used sed to extract values between words SendCommands and end like this sed -n '/SendCommands/,/end/p' ddtt As awk was ...
0
votes
2answers
58 views

How to delete lines where the given part of the line is more than 100 chars?

I know I can delete lines that are longer than 100 chars with this: sed '/^.\{100\}..*/d' But I have the following example line: <a ...
2
votes
2answers
350 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
3
votes
1answer
9k views

Replacing string based on line number

I have a situation where i want to replace a particular string in many files Replace a string AAA with another string BBB but there are lot of strings starting with AAA or ending in AAA ,and i want ...
2
votes
1answer
782 views

exchange two words using sed

I am trying to exchange two words in a line but it doesn't work. For example: "Today is my first day of university" should be "my is Today first day of university" This is what I tried: sed ...
0
votes
3answers
114 views

Grep end regex matching

On OS X, system_profiler SPHardwareDataType outputs: Hardware Overview: Model Name: MacBook Pro Total Number of Cores: 4 L2 Cache (per Core): 256 KB L3 Cache: 8 MB Memory: 8 GB I want to ...
2
votes
1answer
85 views

Deciphering sed commands

I just run across the following sed command: sed "s|^/samba|\\|;s|/|\\|g" I have seen sed substitute commands before. I also know sed allows the usage of any character as a delimeter (| in this ...
3
votes
4answers
604 views

Colored output in less when tailing a logfile

I am in dire need of a way to color my less output while reading a file that is constantly being appended. The file in questions is a Resin servlet container log. My current "implementation" of the ...
1
vote
1answer
126 views

What does x option for sed do actually when exchanging data between hold and pattern buffer?

I dont understand what x does when it comes to exchanging the contents of hold and pattern buffer.Does it exchanges the data between hold and pattern so that any previous data in hold or pattern is ...
1
vote
2answers
260 views

Regex and piped commands with sed

I'm finding really hard to use sed command, plus I can't seem to find well written tutorials. Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
2
votes
2answers
1k views

Using sed to process passwd file

I am trying to learn sed, but I'm having a lot of trouble. What I am trying to do is process my passwd file using a bash script with sed commands to do the following: For every user with group ID ...
1
vote
6answers
8k views

How can I use variables when doing a sed?

I want to do: cat update_via_sed.sh | sed 's/old_name/new_name/' > new_update_via_sed.sh in my program. But I want to use variables, e.g. old_run='old_name_952' new_run='old_name_953' I have ...
2
votes
3answers
335 views

awk, sed, grep, perl… which to print out in this case?

I have this syntax in a file (http response times from analog): <thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
-1
votes
1answer
211 views

Replacing part of a string with another part of that same string [closed]

How would I go about replacing part of a string with another part of that same string, in a bash script, using sed?
3
votes
1answer
63 views

How to edit files in-place while performing operation on the values matching the searched pattern?

Given a list files containing random text and many datetimes in ISO format in it (e.g "2012-07-02T10:47:24+02:00"), how can I find all these datetimes and add 2 hours to each one ? Ideally a solution ...
2
votes
3answers
2k views

Bash commands/script to remove a line from CSV with duplicate in column

I have a lot CSV files that I have combined. However, there are duplicates, but the entire line is not duplicated. I do have a column that I want to use as the criteria to search for a duplicate. ...
1
vote
3answers
604 views

Newbie struggles with grep, sed, awk to filter html

I am a beginner linux user, trying to teach myself how to use linux tools on a cygwin install. I decided to make up a project to try to teach myself the basics of shell scripting and simultaneously ...
3
votes
4answers
1k views

Replacing pattern after nth match is found on each line?

I have a file containing lines: india;austria;japan;chile china;US;nigeria;mexico;russia I want to replace all the occurences of semicolon on each line with e.g. ;NEW;, but starting from the 2nd ...
0
votes
1answer
52 views

How can I update this sed oneliner?

INPUT: $ echo -e 'AAAART5530408XXXX\nAAAAZE6530408XXXX\nAAAART12345678XXXX' AAAART5530408XXXX AAAAZE6530408XXXX AAAART12345678XXXX $ OUTPUT: $ echo -e ...
1
vote
1answer
116 views

How to parse this output and put it into an array?

i have expect script whose output looks like : I would like to extract all words like Gi/02/12 etc in an array or a list. VLAN Name Status Ports ---- ...
0
votes
2answers
913 views

How do i remove all occurences of semicolon from the end of all lines?

These are the steps i am following. `sed 's/[;]+$//g'` also sed 's/;{1,\}$//g'
1
vote
2answers
80 views

Match ids and print original file

I have two files Original: (5000 entries) Chr Position chr1 879108 chr1 881918 chr1 896874 … and a file with allele frequencies (2000 entries) Chr Position MAF chr1 881918 0.007 ...
-1
votes
1answer
318 views

Search low values in mainframe files

I am working with mainframe files and it seems that the low values (x'00') exists in the records in the file which throws off my import for fixed block. Does anyone know how to eliminate those ...
2
votes
2answers
9k views

How can I replace text after a specific word using sed?

I have a file named .ignore. In need to replace the projdir. For example: ignore \..* ignore README projdir Snake I need to replace Snake with, for example, "PacMan". I read the man page, but I ...
0
votes
2answers
207 views

sed extract with multiple options in end pattern

I get some output from a command, I have to extract text between two patterns from the output. Start pattern is fixed. But the end format can be one of two (lets say word2-1 and word2-2). Is there ...
3
votes
7answers
1k views

Is there a faster way to remove a line (given a line number) from a file?

A related question is here. I often have to edit a large file by removing a few lines from the middle of it. I know which lines I wish to remove and I typically do the following: sed ...
-1
votes
2answers
5k views

Bash -Extract characters from string

Suppose I have the following variable $string = 'cat somecommandhere' Now the output of the above cat command is test="Thanks serverfault" I want to extract the value between the quotes and ...
2
votes
1answer
68 views

extracting and copying parts of tex files into new tex files

I have a bunch of tex files in different folders on my system. The goal is to create new tex files (using a template, that has the title page, packages, new commands,...) that combines all the ...
2
votes
1answer
136 views

how do i suppress seds unnessary output while using option -e?

why n option is not working here [root@testgfs2 final]# echo a b c | sed -ne 's/[[:blank:]]/"/gp' -ne 's/^/"/pg' -ne 's/$/"/pg' a"b"c "a"b"c "a"b"c" i just need : "a"b"c" actually ...
2
votes
2answers
397 views

changing pattern by removing spaces?

file : hi hello,new york, , ,brazil site ,brazil january,month is feb , , ,indiana jones task: delete all horizontal space (spaces and tab) between any two comas (like , ,) if ...
6
votes
3answers
1k views

Multi-line replace

I spent ages trying to figure this out. As it happens, I don't need to do it any more; I found another way. But for the sake of my sanity, I'd like to know the answer anyway. It's quite easy to use ...
0
votes
3answers
228 views

For all files that does not contain a string, prepend a string to the file

I am trying to iterate through a list of html files, check to see if {% load static from staticfiles %} exists in the file and if it does not exists, prepend {% load static from staticfiles %} to it. ...
1
vote
2answers
415 views

reading from a file and changing its pattern into an array?

I have a CSV file containging entries like this : ipaddress,VLAN,VLANid 10.192.168.1,vlan-xyz,3 10.192.168.1,vlan-abc,8 10.192.168.1,vlan-mnp,11 10.192.163.24,vlan-llz,3 10.192.163.24,vlan-bbz,5 ...
1
vote
4answers
86 views

How to find what device a file is on (and use that in a script)?

I want to find out what device my file is on so that I can use it in a script. I can get this far: $ df . Filesystem 512-blocks Used Available Capacity Mounted on /dev/disk0s2 498438976 ...
2
votes
4answers
115 views

How do I correct both too many and too few space characters?

I have files that are edited by people other than me. They contain lines that look like this: <E> This is text </E> I use some Bash shell scripts do a bunch of text replacement ...
1
vote
2answers
148 views

sed pattern matching with deletion over a line

I want to delete only some spaces(say 4) after the line$#*425 with space I am not able to complete it please suggest echo "line$#*425 with space " | sed 's/ /\1 \2/g' i am thinking of ...
1
vote
2answers
717 views

Print fields from file only if line starts with a specific word

I have the following file: … LINK=dummy 172.17.100 => 10.218.11 [PATH=/etc] FILE=hosts 172.17.100 => 10.218.11 [PATH=/etc] FILE=network 172.17.100 => 10.218.11 ...
0
votes
2answers
415 views

remove a char string from a command output (sed, or maybe something else)

I'm trying to retrieve the distro name from the lsb_release -i output, but using lsb_release -i | sed 's/Distributor ID: //g' won't do the trick. What am I doing wrong? Or maybe should I change ...
1
vote
1answer
2k views

How to calculate average requests per seconds using awk or sed on Apache logs

I am trying to calculate the average requests per seconds for a specific period of time of my Apache logs. I have been able to narrow the results down to the period I am interested in, as well as ...
3
votes
2answers
714 views

Split log file by time range

I have a log file and would like to cut it into copies of 15min. In the log file the lines start with: dd mmm yyyy hh:mm:ss,xxx e.g. 12 Feb 2013 16:05:02,xxx log text... and the file rotates ...
6
votes
4answers
13k views

Text between two tags

I wanna retrieve whatever is between these two tags – <tr> </tr> – from an html doc. Now I don't have any specific html requirements that would warrant for an html parser. I just plain ...
5
votes
2answers
5k views

How to replace a left parenthesis with sed?

I have to replace ( with some character in my file, and I can't do it. \( is used for grouping in sed and when I used \\( with sed, it treated it as \( character not as just (. It seems like a tricky ...
1
vote
1answer
109 views

using sed for replacing strings with “/”

need to replace < network> with a "192.168.61.0/24" but i am not able to do it with sed, tried sed -i s/"< network>"/"192.168.61.0/24"/g file.sh but this is not working,can some one ...
1
vote
1answer
75 views

sed into csv format

I have a file of the form VL-8299673,30.000,49.000,1.000,21.901,2630.000,428861.000 VL-8299673,1071.000,570.000,35.000,3963.608,632.000,366563.000 ...
1
vote
2answers
112 views

How can fill characters in sed only

I have this file. I want to use only sed, no awk FSDFDSFSD FDSFD FHGDHFDHGHFGHGHGF HHGDF GFDGDFGFDG GFDGFDGFDGDFGDGD I want to fill every odd line appended with 000 so that total characters are 30 ...
4
votes
2answers
309 views

Why does this add spaces? echo “x ax” | sed 's/x\s*/x /'

I want to find a x, and replace the 0 or more following spaces (\s*) with just a single space. echo "x ax" | sed 's/x\s*/x /' For some reason, instead of replacing the spaces with the single space, ...
1
vote
1answer
211 views

Why is it that , to newline is working but newline to , is not working sed?

I have got a text file with a list of first names, and I am trying to replace newline with ,. Here is the command I am using sed 's/\ /,/g' file while the reverse is working sed 's/,/\ /g' file ...
2
votes
3answers
525 views

Use find + sed + cp to find files and copy them to a directory with a different name

I'm trying to copy a bunch of files named folder.jpg into a folder. The problem is because all the files are named the same thing, I need to rename them in the process. I know I can probably do it ...
4
votes
2answers
540 views

Out of memory while using sed with multiline expressions on giant file

I am currently trying to remove all newlines that are not preceded by a closing parenthesis, so I came up with this expression: sed -r -i -e ":a;N;$!ba;s/([^\)])\n/\1/g;d" reallyBigFile.log It does ...