"sed" (stands for stream editor) is a Unix utility that parses and transforms text files. It implements a fairly basic programming language to perform the transformations, but is in fact Turing-complete. Sed on Wikipedia
0
votes
1answer
40 views
Oneliner for multiline regex s/,\n]/]/g?
Can someone provide a simple one-liner to remove certain linebreaks ?
In vim I do :%s/,\n]/]/g
this should be possible with a very simple one-liner IMHO, but how?
0
votes
0answers
27 views
How can I improve or wrap my sed-script?
I instrumented a mvn build to emit profiling data, which I want to analyse later on. Therefore, I made the sed script below, to generate json-data from the profilers output. I call the script with
...
1
vote
2answers
56 views
Replaces images\(.*)“ with images/\1” in all files?
I've got a bunch of html files, and all the img tags have the slashes the wrong way!
Here's an example (except it's one line in the code, split here for ease of viewing)
<a ...
2
votes
2answers
63 views
Removing ANSI color codes from text stream
Examining the output from
perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";'
in a text editor (e.g., vi) shows the following:
^[[37mABC
^[[0m
How would one ...
1
vote
3answers
38 views
sed removal of whitespace
I find that sed often fails to pattern-match whitespace. Consider the following examples:
echo 'A B C' | sed 's/[ \t]*//g'
ABC
echo -e 'A\tB\tC' | sed 's/[ \t]*//g'
A B C
perl ...
0
votes
1answer
48 views
Sed pattern for multiple lines
I want to remove all create table statements from a mysql script, but the statement runs over multiple lines.
Like this: Create table ......NEWLINE... NEWLINE... NEWLINE....;
So I tried this ...
0
votes
1answer
17 views
seq with regex, error message for mysql quotes
Is there some tool that auto quotes regex for seq?
I can't figure out what I'm doing wrong. I always get this error unterminateds' command`
sed -i 's/INSERT INTO `tablename.*`/INSERT INTO ...
0
votes
1answer
42 views
awk + sed + match complex string
I need useful command to match the string "/pci.../pci.../pci..../scsi..../disk..."
with awk or sed? ( I need to put this command in my ksh script )
remark 1 [...] can be any string , and “pci pci ...
0
votes
1answer
36 views
sed + does not work on solaris
I try to use a sed line with a + on a Solaris machine and on a Linux machine.
on Solaris sed does not remove the strings until the first number like I want:
solaris:/ ROOT > echo ...
0
votes
3answers
53 views
Using SED to join 2 fields in CSV and add them at the end of the line
I have a SED problem beyond my knowledge. I have a solar plant that generates CSV files in the format
2012-01-08;00:00;171,297;0,000;
2012-01-08;00:05;171,297;0,000;
...
0
votes
2answers
36 views
Getting values using sed
I am running a script whose output is:
Circuit Packets/Bytes Sent Packets/Bytes Received
2/1 vlan-id 1005 11589119559 14650974869
...
2
votes
3answers
79 views
Hexadecimal to Decimal conversion in Bash
This is the current output in a text file
1 3.491136 C1 00 08 00 DD 92 01 FF
2 3.560963 C1 00 08 00 DD 92 01 FF
3 3.600959 C1 00 08 00 DD 92 01 FF
4 ...
0
votes
0answers
12 views
sed grouping cancels out results?
When running the following sed command under Windows (to uppercase a keyword which isn't part of another word):
"c:\Program Files (x86)\GnuWin32\bin\sed.exe" -e "s/[^a-z]*declare[^a-z]*/DECLARE/I" ...
0
votes
2answers
93 views
How to extract a version number using sed?
I'm trying to find the best regular expression to extract a version number from a string. For example:
echo "Version 1.2.4.1 (release mode)" | sed -ne ...
0
votes
1answer
43 views
sed parsing data: fields (words) separated with whitespace
I'm using sed on Linux, trying to match data lines having three fields, tab separated (but the separation could be any whitespace), as in:
12.3 0a 1b
15.5 0v 1h
17.7 5k 3c
; right now I'm using ...
0
votes
1answer
56 views
Linux sed can't read the file that's right there
grep -r -l --include=*.{html,js,css} "\bAA\b" . | xargs -0 -n 1 sed -i -e "s/\bAA\b/BB/g"
When I ran the above command, I got the following error:
sed: can't read ./login.html : No such file or ...
2
votes
3answers
66 views
combining sed with xargs to obtain a source and output file name
I have a situation where I have some input files like this:
M2U0001.MPG
M2U0180.MPG
And I want to run a command (in a bash shell) on each similarly named file in the directory. I'd like the ...
2
votes
3answers
138 views
Mass Rename Files with bash
I've got a bunch of numbered files like this:
file #01.ext
file #02.ext
file #03.ext
file #04.ext
file #05.ext
And what I want is to make them all have three digits (two leading 0's) instead of ...
2
votes
8answers
62 views
How do I remove similar instances of lines using Unix commands?
I have a file that contains lines that look like the following:
14|geauxtigers|90
14|geauxtigers|null
I want to remove all instances in the file with the null as the last term. Is there a way to do ...
2
votes
1answer
80 views
How can I automate modifying key/value pairs in a shell script?
I often want to automate this sort of task in a shell script:
if the line:
SOMEKEY=SOMEVALUE
exists in a file, then change it to
SOMEKEY=SOMEOTHERVALUE
otherwise, append the line ...
1
vote
1answer
35 views
Bash file redirection works differently from script
$ cat test.txt
foo
bar
This sed command replaces the first line in text.txt with "baz". It works fine from command line:
$ sed "1s%.*%baz%" "test.txt" > "test.txt"
$ cat test.txt
baz
bar
I'd ...
0
votes
4answers
58 views
Extract substring using bash
All,
I have file names that will be always in the following format
"rX_Q_Y_filename.mp3" where X and Y are numbers (0-9).
FYI, X and Y in the filename can be 1 or more digits
example ...
2
votes
2answers
94 views
Unix one-liner to quote all words on a line
I have a text file which has lines consisting of words (separated by spaces) and I want to put quotes around all of the words.
For example:
Lorem ipsum dolor sit amet
consectetur
adipisicing ...
0
votes
2answers
91 views
RegEx find and replace with sed, matching group and replacing on condition
Is this possible with sed?
I'm actually in iTunes using "Track Name Edit with sed" from Doug's Scripts, and I have a collection of tracks that are titled in one of two ways:
Identical string - ...
1
vote
2answers
88 views
Join two lines with awk or sed
If I have:
foo
bar
..and I'd like to awk/sed this to:
foo-bar
..what's the syntax?
I'm trying to use System Profiler on OS X 10.6.x:
system_profiler SPMemoryDataType | awk '/Type/ {print $2} ...
0
votes
4answers
76 views
my sed expression does not work
I want to use sed to comment out a certain command in a js file. The command is called processLoad(..). I came up with expression below but it doesn't do what I expect it to do. The computer that I ...
0
votes
2answers
72 views
Truncate all files in a directory after underscore?
I have a directory with a couple thousand images in it. Most of them have sensible filenames like SD-000.tif SD-001.tif BX-000.tif etc...
However probably ~25% of them have names like BX-003_old.tif ...
2
votes
3answers
126 views
In linux how do I to get ' quote ` back-tic through the shell into sed.
In linux how do I to get the ascii decimal/hex/oct code from a char or a ascii char from a decimal/hex/oct code.
I see from the gnu sed user manual that I can use the \d# \o# \x#
to specify a ...
0
votes
1answer
202 views
Sed error “sed: -e expression #1, char [#]: extra characters after command”
sed '/\r$/ {N s/\n//}'
sed: -e expression #1, char 10: extra characters after command
I want to understand what is wrong with my command line.
When I can do the some of following in a script ...
1
vote
2answers
52 views
Delete directories dated Jan, 2010 on Linux
Hi All i want to use the following command to delete directories dated Jan 2010 only
ls -lh | awk '{print $6 " " $9}' | sed -n '/Jan/p' | awk '{print $2}' >>/tmp/file_list
The above command will ...
0
votes
2answers
69 views
Using sed to replace a *large* number of variables in a file
I have a large number of log files, on a linux box, I need to cleanse sensitive data from before sending to a third party. I have used the below script on previous occasions to perform this task, and ...
1
vote
1answer
61 views
Delete all occurences of any word matching a partial string in sed
Assume that I have the following line:
group blue:green yellow green redtomblue black !greyTOMwhilte !purple redblue
I need to delete from it all words that contain the string "tom" or "TOM" using ...
0
votes
2answers
45 views
lines identical except for their first word, put the first word in a variable
I have file(sudoers) in which lines can be identical except for the first word in them (different users can execute the same set of commands). I am able to extract such a line using the command:
# ...
2
votes
1answer
137 views
how to remove html comment tags using sed?
I want to remove comment tags in an html file.
<!--- <script save and execute me> -->
must become:
<script save and execute me>
I tried
sed -i s_^<!-- \(.*\) -->$_\1_ ...
2
votes
3answers
156 views
Newlines in sed on Mac OS X
I find that \n doesn't work in sed under Mac OS X.
Specifically, say I want to break the words separated by a single space into lines:
# input
foo bar
I use,
echo "foo bar" | sed 's/ /\n/'
But ...
3
votes
2answers
187 views
sed: Replace an unknown number of patterns on the same line
I'm trying to use sed to search for a certain 'primary' pattern that may exist on several lines, with each primary pattern followed by an --unknown-- number of 'secondary' patterns.
The lines ...
1
vote
4answers
311 views
How do I write a script that sums the numbers in a file?
I'd like to sum up numbers in a plain text file. Is there somehow I can do this with a command or a bash script?
Say I want to extract the number in a pattern that looks like this:
… text text …
...
0
votes
1answer
95 views
Command line solution for removing parts from a binary file?
I have a binary file and I would like to remove parts from. By removing I mean deleting those parts and thus making the file's size smaller.
The parts would be between two ASCII strings. So, for ...
0
votes
2answers
90 views
What is the ^I character and how do I find it with sed?
I usually import data from csv files to MySQL, but my data provider leaves NULL entries as "", so I need to replace "" with "\N". This is easy enough with a script like
for csvfile in *.csv
do
...
0
votes
3answers
87 views
Format change data in file. Multiple sed commands?
I'd like some advice on changing the formatting of some data in a file.
I have a large amount of data in a file. This is a output from a large Fortran program, it is formatted for a latex table. I ...
0
votes
2answers
238 views
sed print only pattern match
I am trying to get versions for services in a gnmap file. A typical line looks like:
Host: 192.x.x.x () Ports: 21/open/tcp//ftp//HP JetDirect ftpd/, 23/open/tcp//telnet//HP JetDirect printer ...
0
votes
1answer
53 views
Use sed to modify and execute previous command
I've got a bunch of pdf files that are joined with a very long command line sitting in a directory. Some are in English and some are in French, differentiated by _e.pdf and _f.pdf.
Because they're ...
3
votes
2answers
96 views
How greedy is sed in matching patterns?
I know sed is greedy when matching patterns. But, how greedy is it?
Consider these examples.
$ echo 'foobar123' | sed 's/[0-9]*/(&)/'
()foobar123
$ echo 'foobar123' | sed ...
2
votes
2answers
166 views
Looking for a regular expression to extract http valid URIs from a file?
I'm looking for a regular expression which can extract http URIs from a file (arbitrary text). Note that text can have word "http" but that word might or might not represent a valid URI address.
...
1
vote
3answers
147 views
Simple if-statement that checks if line is in a file
I am trying to create a very simple login console for a script that I have, this is just for fun to see if it works.
Basically what I thought would be possible is this.
I will read in the file ...
2
votes
2answers
78 views
sed in bash not working
I am trying to use the stream editor sed in bash to replace a string in a file to a new string that I entered, I have this thus far:
echo "name to change"
read updatenaamold
echo "enter new name:"
...
1
vote
4answers
176 views
How to use sed on Linux to get values from file name?
how to retrive every portion separately from following file name?
DSA4020_frontcover_20346501_2011-05.doc
I want to retrieve informations as below;
name = DSA4020
type = frontcover
id = 20346501
...
3
votes
1answer
405 views
how to use sed to remove null bytes?
What is the sed incantation to remove null bytes from a file? I'm trying:
s/\000//g
but that is stripping out strings of zeroes.
s/\x00//g
seems to have no effect. I'm trying to do this in a ...
0
votes
0answers
18 views
Match reference and footnote in same file, and replace reference with footnote
I have several text files (documents with about 1000 footnotes pasted from a word processor) with the following format:
An inline reference in asterisks*1* is one,
two or three digits*2* but ...
0
votes
0answers
18 views
Dependency rules using sed
I am trying to create dependency files using this rule, and I am having trouble with the $@.$$$$
%.d: %.cpp
$(CC) -MM $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
...