sed

question of sed replace

hi i have a config file xml <tflow name="CENTRE" inputDTD="/JOBS/cnav/etc/jobReporting/batch/dtd/dtd-ContactCentre.dtd" inputFile="/JOBS/cnav/etc/jobReporting/import/2010.05.02.CONTACTCENTRE.xml" logPath="/JOBS/cnav/etc/jobReporting/logs/" rejectPath="/JOBS/cnav/etc/jobReporting/rejets/"/>...

sed: group capturing

Is there any way to tell sed to output only captured groups? for example given by input: This is a sample 123 text and some 987 numbers and pattern /([\d]+)/ I could get only 123 and 987 output in the way formatted by back references perhaps? ...

output of one command is argument of another

Is there any way to fit in 1 line using the pipes the following: output of sha1sum $(xpi) | grep -Eow '^[^ ]+' goes instead of 456 sed 's/@version@/456/' input.txt > output.txt ...

Processing a tab delimited file with shell script processing

Hello, normally I would use Python/Perl for this procedure but I find myself (for political reasons) having to pull this off using a bash shell. I have a large tab delimited file that contains six columns and the second column is integers. I need to shell script a solution that would verify that the file indeed is six columns and that t...

bash split text into limited character buckets (array member)

i have text such as http://pastebin.com/H8zTbG54 we can say this text is set of rules splitted by "OR" at the end of lines i need to put set of lines(rules) into buckets (bash array members) but i have character limit for each array member which is 1024 so each array member should contain set of rules but character count for each ...

replace line with sed in csh

Hello, I am trying to change the content of a specific line in a batch of files. I thought that would be a piece of cake but for some reason, nothing happens, so I guess I am missing something. Line 8 should have been replaced. Here the csh script I used: #!/bin/csh # # replace context in line xxx by yyy # 2010/05/07 set files = `ls ...

sed character replacement in portion of a line

New to sed and could use some help. I would like to turn this "a/b/c a/b/c" into this "a/b/c a-b-c". where a/b/c is any path. thanks ...

Substitute alt attribute with title attribute using sed

I have a PCRE regex that looks like this s/(<input.+?)alt(=".+?".*?>)/$1title$2/ Can anybody help me with making that work on sed? Eventually can anybody point me to some guide/blog post/whatever that explains differences between sed regex and PCRE? ...

Linux command line script to renumber files backward

I have JPG files numbered 3006-3057 that I would like to reverse number. I would be content renaming them by adding a backwards number count to the beginning of the name: img_3006.jpg > 99_img_3006.jpg and img_3057.jpg > 48_img_3057.jpg. ...

Tab Delimited to Comma Separated file in UNIX - One liner?

I have a tab delimited file (MySQL Out file). I want to convert it into CSV file. I got everything working except for replacing NULLs to nothing or spaces. What I have is : sed -e 's/^/"/; s/$/"/; s/\t/","/g;' < file.csv > file1.csv How to also replace NULLs in the same line. The following doesn't work. sed -e 's/NULL//; s/^/"/; s/$...

multiline sed using backreferences...

Hi, I'm converting patch scripts using a commandline script - within these scripts there's the combination two lines like: --- /dev/null +++ filename.txt which needs to be converted to: --- filename.txt +++ filename.txt Initially I tried: less file.diff | sed -e "s/---\/dev\null\n+++ \(.*\)/--- \1\n+++ \1/" But I had to find ou...

sed: search and replace string with line number

Hi volks, I have a XML file with a lot of empty tag attributes. For instance: <mytag id=""> <ontent>aaa</content> </mytag> <mytag id=""> <ontent>bbb</content> </mytag> <mytag id=""> <ontent>ccc</content> </mytag> Now I want to replace id="" with e.g. id="2443" (id="[linenumber]") I tried to do this with sed, but I did not get ...

Help with MySQL (.sql) and Shell Script

How do I call the following in a .sql file? mysql -u username -h serverip db -e "select a, b, c, d from mytable" > '/home/dump/result.txt'; I will then have to convert the tab separated file to csv for which I want to use sed. Is there a way to do it all in one line? (append sed command to convert the .txt file to csv) How to use ...

Using or in multiline sed replacement

hi folks I'm confused with a seeming simple part of sed - the or statement. I wrote the following sed which parses an event file with multiple events encapsulated between event tags and then prints the output of each event on 1 line each: machinename:~$ sed -n "/<event/,/<\/event>/ {/<result/{s/.*result value=\" \(.*\)\"\/>.*/\1/g; p};...

SED whitespace removal within a string

I'm trying to use sed to replace whitespace within a string. For example, given the line: var test = 'Some test text here.'; I want to get: var test = 'Sometesttexthere.'; I've tried using (\x27 matches the '): sed 's|\x27\([^\x27[:space:]]*\)[[:space:]]|\x27\1|g but that just gives var test = 'Sometest text here.'; Any ideas...

Replace CR/LF in a text file only after a certain column

I have a large text file I would like to put on my ebook-reader, but the formatting becomes all wrong because all lines are hard wrapped at or before column 80 with CR/LF, and paragraphs/headers are not marked differently, only a single CR/LF there too. What I would like is to replace all CR/LF's after column 75 with a space. That would...

Using sed with html data

I'm having some problems using sed in combination with html. The following sample illustrates the problem: HTML="<html><body>ENTRY</body><html>" TABLE="<table></table>" echo $HTML | sed -e s/ENTRY/$TABLE/ This outputs: sed: -e expression #1, char 18: unknown option to `s' If I leave out the / from $TABLE so that it becomes <table><...

repeat string in a line using sed

I would like to repeat each line's content of a file, any quick solution using sed. supposed the input file is abc def 123 The expected ouput is: abcabc defdef 123123 Thank you for your help ...

Need help with a regex (sed)

I want to transform a line that looks like this: any text #any text# ===#text#text#text#===# into: any text #any text# ===#texttexttext===# As you can see above I want to remove the # between ===# and ===# The number of # that are supposed to be removed can be any number. Can I do this with sed? ...

sed script to remove file name duplicates

Dear community, I hope the below task will be very easy for sed lovers. I am not sed-guru, but I need to express the following task in sed, as sed is more popular on Linux systems. The input text stream is something which is produced by "make depends" and looks like following: pgm2asc.o: pgm2asc.c ../include/config.h amiga.h list.h pg...