sed

Whats the difference between sed -E and sed -e

I'm working on some old code and I found that I used to use sed -E 's/findText/replaceWith/g' #findText would contain a regex but I now try sed -e 's/findText/replaceWith/g' It seems to do the same thing, or does it? I kinda remember there being a reason I done it but I can't remember and doing "man sed" doesn't help as they don'...

sed regexp in a bash script

Hello! I want to extract a certain part of a string, if it exists. I'm interested in the xml filename, i.e i want whats between an "_" and ".xml". This is ok, it prints "555" MYSTRING=`echo "/sdd/ee/publ/xmlfile_555.xml" | sed 's/^.*_\([0-9]*\).xml/\1/'` echo "STRING = $MYSTRING" This is not ok because it returns the whole string. I...

sed/awk + count char until relevant char

hi all Dear friends I have the following: PARAM=1,2,3=,4,5,6,=,7#,8,9 How to count by sed/awk the even "=" character between PARAM until "#" character For example PARAM=1,2,3=,4,5,6,=,7#,8,9 Then sed/awk should return 3 OR PARAM=1,2,3=,4=,5=,6,=,7#,=8,9 Then sed/awk should return 5 THX yael ...

how to optimize a wordlist for the english language

i'm looking to optimize a wordlist for the english language using sed or a similar linux application.. in order to do this i need to: Remove lines containing anything except a-z, 0-9, or special characters Remove urls - maybe detection of the "\" character Remove lines over 16 characters long, and 4 characters or shorter. (5-16 chars...

Problem formatting a find with sed output

Hi I'm trying to clean a site from a js-trojan for a customer, it has added: <script src='http://nt02.co.in/3'&gt;&lt;/script&gt; to all html-pages. Since it's too many files to manually clean I tried to a do find like this: find ./ -type f -exec sed -e "s\<script src='http://nt02.co.in/3'&gt;&lt;/script&gt;\ \g" {} > {} \; Problem ...

awk + remove all not uniq lines except the first line uniq (FILE NAME)

hi I have the following file How to remove by sed all FILE NAME lines except the first uniq FILE NAME For example need to remove all FILE NAME lines from the file except the first: FILE NAME: /dir1/dir2/dir3/dir4/dir5/file FILE NAME: /dirA/dirB/dirC/dirD/dirE/file the file: FILE NAME: /dir1/dir2/dir3/dir4/dir5/file PARAMETER NAME: bl...

sed + replace word on directory PATH

Hi all How to replace the <x> with word Before_last_dir only on the dir that located before the last dir (according to this example – dir4) echo "/dir1/dir2/dir3<x>/dir4<x>/dir5<x>" |sed s"/<x>/Before_last_dir/g" Another example echo "/dirA<x>/dirB<x>/dirC<x> >" |sed s"/<x>/Before_last_dir/g" should be /dirA<x>/dirBBefore_l...

sed + change small and capital letter

hi all I have the following echo "<x>small<X>capital" | sed s'/<x>/WORD/'g How to change sed syntax in order to replace x and X with WORD in this sed . sed replace only the small letter x THX yael ...

How to remove last directory from a path with sed (not using dirname)?

How to remove the last dir with sed, like this: echo "/dir1/dir2/dir3/dir4" | sed ..... So I would get /dir1/dir2/dir3. ...

Remove links from text file

Hi, how can I remove links from a raw html text? I've got: Foo bar <a href="http://www.foo.com"&gt;blah&lt;/a&gt; bar foo and want to get: Foo bar blah bar foo afterwards. ...

How can I alter a file and write only the changes to disk - basically, sed (python)?

Let's say I have a file /etc/conf1 it's contents are along the lines of option = banana name = monkey operation = eat and let's say I want to replace "monkey" with "ostrich". How can I do that without reading the file to memory, altering it and then just writing it all back? Basically, how can I modify the file "in place"? ...

sed help remove malwarm code from multi files

Hello guys ive this malwarm code in so many files html and php on the server i need to remove them using sed -i expression search all files on dir /home/ find infected files and remove the code replace it withe white space any help ? <script language=JavaScript>var usikwseoomg = 'PaBUTyjaZYg3cPaBUTyjaZYg69PaBUTyjaZYg66';var nimbchn...

using sed in perl

Hi , I have a file with the following entries --INFO----- Command processing: Name='shayam' Age='19' Project='Alwa' --ERROR---- Failed to process --INFO----- Command processing: Name='ram' Age='23' Project='Alwa' --INFO----- Command processing: Name='raja' Age='24' Project='Alwa' --INFO----- Command processing: Name='shyla' Ag...

Joining two consecutive lines awk sed

How would i join two lines usung awk or sed? for eg: i have data like below: abcd joinabcd efgh joinefgh ijkl joinijkl i need oupput like below: joinabcdabcd joinefghefgh joinijklijkl ...

Looking for a more efficient (and portable) way to obtain (numeric) file permissions in unix

Short background: I need to monitor the permissions on a unix file (a directory) with ZABBIX to see if/when they change. ZABBIX doesn't have any built in like vfs.file.mode[xxxx] for this, so I had to roll my own UserParameter, with a numeric type. What I do so far, is use ls -l | cut -c 2-10 to get the rwxr-xr-xpart, and then use sed t...

sed - how to delete everything but the last n lines ?

On a windows box (no CYGWIN etc) using sed how can you "delete all but the last n lines" from a text file ? On *nix you could get tail/cat/wc involved to pre-process the input file but how can you do this using pure sed ? [FWIW the sed is the GNU sed; the platform is Windows 2003]. ...

Using sed in a makefile; how to escape variables?

I am writing a generic makefile to build static libraries. It seems to work well so far, except for the line calling sed: # Generic makefile to build a static library ARCH = linux CFLAGS = -O3 -Wall SOURCES = src BUILD_DIR = build/$(ARCH) TARGET = $(BUILD_DIR)/libz.a CFILES = $(foreach dir,$(SOURCES),$(wildcard ...

How to use a bash script variable with sed

I execute the following bash script: #!/bin/bash version=$1 echo $version sed 's/\${version.number}/$version/' template.txt > readme.txt I'm expecting to replace all instances of ${version.number} with the contents of the variable "version". Instead the literal text $version is being inserted. What do I need to do to make sed use the...

How do I search for anything between these tags

How do I search for anything between these tags, I would like to list all occurences where there is some value between the f:facet xml element <f:facet name="header">Name</f:facet> ...

Shell script to find, search and replace array of strings in a file

This is linked to another question/code-golf i asked on http://stackoverflow.com/questions/3171552/code-golf-color-highlighting-of-repeated-text I've got a file 'sample1.txt' with the following content: LoremIpsumissimplydummytextoftheprintingandtypesettingindustry.LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenan...