"sed" ("stream editor") is a Unix utility that parses and transforms text files.
0
votes
2answers
411 views
Sed command to remove everything following the colon
I have the collection of text files containing/not the phrase (B core file).
Then I tried this:
sudo find / -type f -name core | xargs file | grep 'B core file' | sed 's/:ELF.*//g' | xargs rm -f
...
2
votes
2answers
4k views
Using sed to replace string with special characters in XML file
I am having difficulty getting sed to replace a string of text in an XML file, despite the fact that I have no trouble using grep to find that same string. Since the new string and old string to be ...
1
vote
3answers
736 views
SED: Search a alphanumeric string and replace it
Guys,
I need to search and replace an alphanumeric string using SED.
Search String: Test:rXXXXX, where XXXXX will always be a 5 digit number
Replace String: Test:rYYYYY, where YYYYY will always be ...
2
votes
3answers
422 views
Use sed — or what — to match and delete multiple lines, i.e. “Directory” followed by two blank lines?
I have a file listing all the directories on a hard drive. I want to delete all the instances of a line with the word "Directory" followed by two blank lines. That is, I want to delete all three of ...
2
votes
2answers
2k views
Sed only print matched expression
How to make sed only print the matched expression?
I want to rewrite strings like "Battery 0: Charging, 44%, charging" to
"Battery: 44%". I tried the following:
sed -n '/\([0-9]*%\)/c Battery: \1'
...
0
votes
2answers
239 views
Shell: Trim whitespace in the beginning of files
I have 20k files in here, and at least 1000 of them having white space in the beginning.
How can I remove whitespace with sed for example? The problem is, that it may apear some duplicated file ...
2
votes
2answers
588 views
How to remove comments in all files including in subdirectories?
to remove comments (start with # and /* comment */) in settings.php, below command is just works fine:
sed '/^\#/d' settings.php > outp.txt
mv outp.txt settings.php
sed '/\/\*/,/*\//d; /^\/\//d; ...
3
votes
3answers
1k views
sed: replace any number of occurrences of a certain pattern
Given this input:
"hell -- 'this -- world --is'-- beautiful' --thanks-- we'-- are-- here"
I want to replace every '--' in between single quotes with 'X-X-X' using sed. It should give the ...
0
votes
1answer
231 views
Textmate: Find and replace across project with contents of one file from said project
I have a regular expression to find the text i want (i wrapped the relevant section in custom tags) and i can do it by hand without much issue but what I want is a way to automatically find and ...
2
votes
2answers
1k views
sed syntax to remove xml
I'm trying to sanitize this output from it's metadata to plug this output into GreekTools, but I am getting stuck on sed.
curl --silent www.brainyquote.com | egrep '(span class="body")|(span ...
0
votes
2answers
122 views
sed e.g.: “1” to “01” - how?
if someone can write a better subject, then i would be happy:D
INPUT:
201103 1 /mnt/hdd/PUB/SOMETHING
201102 7 /mnt/hdd/PUB/SOMETH ING
201103 11 /mnt/hdd/PUB/SO METHING
201104 3 /mnt/hdd/PUB/SOMET ...
0
votes
3answers
2k views
Use sed to parse specific values out of a space-separated string
I have a file with lines like:
0 6 973 1346 2318 456 431 93 58 1 1 0 0 0 0
I want to extract the 1st, 4th and 5th number and save them in variables in bash for further use. In the example above the ...
3
votes
5answers
2k views
How to print last character of a file
In Unix, using a simple command like sed, is there a way to print the last character of a file?
1
vote
2answers
80 views
Trying to cleanse log files on a Linux machine, currently using sed
I have a large amount of log files that I need to remove sensitive data from. The sensitive data is provided to me in a text file and is prone to change.
I had hoped to do the equivalent of this:
...
0
votes
2answers
1k views
Exclude some matches with sed
I have a series of files with entries(namespaces in source code) like
FW.WGS.Web.HHH.Controls, FW.WGS.Web.HHH.Email, FW.WGS.Web.HHH.Account, etc and some with entries
FW.WGS.Web.Controls, ...
2
votes
2answers
1k views
Search & replace back slashes to forward slashes in windows
Lately I've been needing to delete new untracked files from my versioning system. Being in linux I use:
hg status -un|xargs rm
And it works nice, but when doing it in windows, hg status lists paths ...
3
votes
4answers
772 views
Search for and print only matched pattern
I have some huge xml text files. I need to write a script to find and print a specific tag only. I tried sed and grep but they both return the whole line.
Using SunOS 5.x, so not all linux commands ...
5
votes
3answers
832 views
Am I using sed properly to perform this conditional replace? Is there a better way?
I have a space-delimited file that's about 3200 lines long. Each line contains 7+ fields.
What I would like to do is edit the file with sed so that every line containing a certain variable in field 5 ...
1
vote
4answers
1k views
using sed to replace two patterns within a larger pattern
Using sed how could I replace two patterns within a larger pattern on a single line?
Given a single line of text I want to find a pattern (Let's call this the outer pattern) and then within that ...
1
vote
2answers
690 views
sed + add char before each number
I want to add a "/" before each number using sed:
echo 1 2 3 4 5 6 7 | sed 's/[ ^]*/&\//g'
/1 /2 /3 /4 /5 /6 /7/
When I use this syntax, why do I get the "/" after 7? How can I fix my ...
2
votes
3answers
2k views
delete only first hit /match with sed
$ echo -e "AsometAhingA\nsomethingA\nASomethiAng"
AsometAhingA
somethingA
ASomethiAng
$ echo -e "AsometAhingA\nsomethingA\nASomethiAng" | sed "s/A//"
sometAhingA
something
SomethiAng
$
I know that ...
1
vote
2answers
293 views
Passing the output of the last command to sed as an argument
Basically, I'm wanting to automate adding something to xorg.conf in the right place, I've used some commands to get the line number of the line I want to manipulate, but I'm not really sure how to go ...
1
vote
2answers
879 views
Sed oneliner to get filename and containing directory
I need to extract the filename and containing directory from a full path (DOS syntax). I need to do this using sed as it is part of a larger regular expression.
Example input: ...
4
votes
2answers
871 views
Use sed command to replace , appearing between numbers
I have a CSV file where data are in the following format
|001|,|abc,def|,123456,789,|aaa|,|bbb|,444,555,666
I want to replace only those "," that appears between numbers with some other character ...
1
vote
1answer
532 views
Batch renaming of files in a directory using sed
I run a script which generated about 10k files in a directory. I just discovered that there is a bug in the script which causes some filenames to have a carriage return (presumably a '\n' character).
...
1
vote
1answer
171 views
Removing the last tab of a line in a file
I have a text file which consists of tab delimted fields terminated with a CR/LF. Before the CR/LF an extra tab has been inserted effectively creating a blank field at the end of every line.
I would ...
4
votes
1answer
838 views
How can I use sed in /etc/apache2/sites-available?
I'm attempting to write a script that uses sed to copy the default file for apache and writes a new file, replacing /var/www ($DOC_ROOT below) with my own directory, $NEW_SITES_DIR. However, sed isn't ...
4
votes
3answers
1k views
How can I delete U+200B (Zero-width space) using sed
I have a very large file that has zero-width spaces scattered throughout. It takes too long to open and edit using vi so I'd like to delete all instances of the character using sed. The problem is, ...
1
vote
2answers
237 views
sed + cut line before “;” seperator
how to perform by sed in order to print the line until ";" character
echo "NUMBER = 3247 FULL DUPLEX ; speed=343 434 " | sed .....
need the following output
NUMBER = 3247 FULL DUPLEX ...
3
votes
4answers
2k views
List only the device names of all available network interfaces
I want to get a list of all available Network-Device Names on my Linux server. I figured that
netstat -a
would do the job, however netstat produces quite much output:
eth0 Link encap:Ethernet ...
1
vote
2answers
2k views
How can I zero pad a particular field in a text file?
I have a file like this:
123123213,456,be
124243233,4346,ytr
123123123,436535,uytr
324234324,322,yt
234324323,32,tyutr
I want to zero-pad the middle field to give the result:
123123213,00000456,be
...
2
votes
2answers
559 views
Increment one value in a text line, using script
I have a text file as input. I need to filter that through some program, SED, AWK, whatever, where i need to increment a value in a particular line every time i run the script.
What's the best way ...
1
vote
3answers
1k views
Using sed to replace text from a list of files from find
Given the following find command:
find . | xargs grep 'userTools' -sl
How can I use sed on the results of that command?
output:
./file1.ext
./file2.ext
./file3.ext
1
vote
2answers
456 views
Mass renaming files, removing dots
I want to rename files as to delete unneccessary dots. ie:
File.something.jpg -> Filesomething.jpg
I.Have.Too.Many.Dots.png -> IHaveTooManyDots.png
How can this be done? find -name *.*.* ...
0
votes
2answers
554 views
Moving characters to the end of line (EOL) with SED
Any time the word “The” appears at the beginning of a line, I want to move it to the end of the line and capitalize the new first word in the line. For example, “The heaven” becomes “Heaven the”. I'm ...
1
vote
1answer
332 views
sed && svn problem
i have an svn working copy which i executed the following command in
find ./source * -type f -exec sed "s/@version 0.5.3/@version 0.5.4/" -i {} \;
the files are all updated but svn doesn't ...
1
vote
1answer
1k views
Using sed, how do I insert text above the first match found?
I'm using sed to modify a codebase. I'm trying to add an [assembly: .. ] reference and for readability's sake I'd like it to appear as the first [assembly: ] reference.
How might I do this in sed?
2
votes
2answers
175 views
change the number format
Hello
I have a lot of lines like below:
123;XXXXXXXXXXXXXXX;ABCDE;YYYYYYYY;08082010;000000000000000;03/08/10;110000;ZZZZZZZZZZZZZZZZZ;0002
I just want to change the number format (15 digit) ...
7
votes
1answer
2k views
Can GNU sed (for Windows) handle Unicode? If so, is it a code-page/locale issue, or a switch?
I've been using GNU SED on and off for a couple of years now. It spins me out a bit sometimes, but it does a good job... for single-byte char sets!
I now and then notice references to GNU SED being ...
0
votes
4answers
1k views
Unix: Search and replace in file names
Using sed, I can search and replace text in a file. Is there a way I can do search and replace of filenames? For example if I have a bunch of files in a folder with names like these:
foo01
foo02
...
0
votes
2answers
76 views
Linux file content replacement issue
I am using Linux Red Hat 5 Enterprise version.
For all files in the current directory, I want to replace all occurrences of /foo/goo/zoo (which are contained in file contents) to /a/b/c.
Any ideas ...
1
vote
1answer
3k views
sed to remove all whitespace from a line
I am wanting to use sed to remove all space characters from a text file. At present I am using this:
sed 's/ //' test.txt > test2.txt
This works in the sense that it removes the first space ...
1
vote
3answers
665 views
csv averages on linux command line
Hey I have a big file full of records like this
1, 2, 4, 5, 6
1, 3, 5, 6, 3
1, 4, 5, 6, 6
2, 4, 5, 5, 5
2, 3, 4, 5, 2
anyway i need to take the average of all rows with the same 1st number(key). ...
0
votes
8answers
221 views
Unix command to list the portion of the end of a log file from a line containing only hyphens to end of file
I have a long log file where each entry begins with a line containg only hyphens.
0
votes
3answers
3k views
sed + How to delete single character after other character in line by sed
How to delete single character after other character in line by sed
For example
LINE="ABCDE 123 |@ TEST"
I want to delete the @ character only if it exist after the first "|" character in LINE
...
1
vote
3answers
527 views
sed + delete the third char from line
the following sed syntax delete the first @ character if exist in string
sed 's/^@\(.*\)/\1/'
How to change the follwoing sed syntax in order to delete the third character?
For example :
In the ...
4
votes
2answers
3k views
Delete the first known character in a string with sed
How does one delete the first known character in a string with sed?
For example, say I want to delete the first character (which is @) in the string "@ABCDEFG1234"
I want sed to verify whether "@" ...
0
votes
1answer
674 views
Solaris bash script / search and append field to end of line in /etc/group
I need a bash script that will modify /etc/group to append and delete NIS users to specific local groups on a Solaris 10u8 system. Preferable one or two functions with uid and groupname as varibles.
...
0
votes
1answer
431 views
sed or grep or awk to match very very long lines
more file
param1=" 1,deerfntjefnerjfntrjgntrjnvgrvgrtbvggfrjbntr*rfr4fv*frfftrjgtrignmtignmtyightygjn 2,3,4,5,6,7,8,
...
1
vote
2answers
290 views
sed how to ignore remarked lines
hi all
I have the following sed command in my script
sed -i "/$PARAM/s/$OLD/$BEW/g" $FILE
this sed command replace the OLD value to new in the line that PARAMETER exsit
but I need also ...