Sed is a command-line stream editor for filtering and transforming text.
2
votes
2answers
43 views
sed command to leave two decimals and remove the rest after comma
I have a numeric value, for example 19.3478 or 22.456 or 10. I would like to remove extra decimals if there are more than two decimals, so that there is never more than two decimals after the comma. ...
2
votes
3answers
94 views
Easy way to parse syslog date format
I'd like to write a script that analyses the last week's syslog.
But my syslog logs in a stupid date format, e.g. "May 22". If it logged as 2013-05-22, this task would be trivial.
Is there a way ...
2
votes
1answer
30 views
SED Showing CRLF While Vim Not Showing
Why sed l\;q shows a CRLF while opening the file in Vim with :set list doesn't show any CRLF
2
votes
3answers
54 views
How to sed a range of lines?
I have this:
sed -i '/^$/d' temp_spec.rb
which is stripping blank lines and works well. How can I make it only do this for lines 5-999 (or ideally 5 to end-of-file).
I tried:
sed -n5,999 -i ...
3
votes
3answers
60 views
How to select 30 files and do a bunch of sed commands on them
I want new copies of the files, so I want to do something like:
dir *.rb
foreach file
make a copy of the file, e.g. 'blob.rb' to 'blob_processed.rb'
do the 50 sed commands to process the ...
2
votes
5answers
280 views
Can sed remove 'double' newline characters?
I have a document with a lot of empty lines.
How can I remove them when there are 2 or more together.
I tried sed "s/\n\n//" file but it didn't work. No error.
1
vote
3answers
83 views
sed - how to replace a single quote?
This works fine:
sed -i 's# @driver.find_element(:xpath, "//a\[contains(@href,##' temp_spec.rb
against a source of
@driver.find_element(:xpath, "//a[contains(@href,'change_district')]").click
...
4
votes
4answers
111 views
sed how to substitute when string has “http://” in it?
I have a file xx that has the following contents:
@base_url = "http://dmstaffing-stage.herokuapp.com/"
I want to use sed to eliminate this line (replace with nothing). I have used this sed ...
3
votes
2answers
47 views
How to only substitute lines that match several patterns in sed?
$ echo -e 'CH12\nCH23au' | sed '/^CH/s=^=<b>='
<b>CH12
<b>CH23au
I know I can match lines starting with CH by ^CH but how can I match multiple patterns?
Example:
Input:
CH12
...
2
votes
0answers
65 views
sed couldn't flush stdout no space left on device?
What could be the reason for this error :
sed couldn't flush stdout no space left on device
This is come of the stuff that i am doing at last in my code
sed -n '/.*needs to be executed ...
1
vote
3answers
50 views
How to share a GNU sed script between Linux and Mac OS X
I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
3
votes
3answers
75 views
sed + how to remove character/s that start or ended on each number
How do I remove the . character(s) that start in the beginning of each number or end on each number?
Remark – perl one liner also good alternative for sed.
Example input:
.23.12.44.5.
.233.3.3.3
...
3
votes
3answers
67 views
checking data in columns when a data or some may be missing or present?
I am not sure if this possible.
say i have columns like :
Team Colour Game Rainfall PlayerName
XYZ Blue Cricket Yes Kapil
suppose i need to search ...
2
votes
2answers
49 views
remove only the first blank line sed
there are similar questions here but none matches my problem exactly.
How do I remove only the first blank line from a file using sed?
Let's say I have
a
b
c
And I want
a
b
c
As output.
4
votes
3answers
82 views
Why is sed giving me an error about an unterminated `s'?
I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like:
sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
3
votes
3answers
42 views
how to form a sed expression containing escaped characters
Given a sed expression (and GNU sed 4.2.2 on ArchLinux)
/match/i\tline1\n\tline2
which should insert two tab-indented lines above the match, I find that the escaping of the first character (in the ...
1
vote
2answers
62 views
Split using sed
I have to split
[X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000
at the pipes and output those line whose 2nd and 3rd argument are different.
2
votes
3answers
80 views
Use sed to find whole word and replace
I have the following block of text in a file:
test3.legacy test4.legacy test3 test3.kami
I only want to search for test3 as a whole and replace it with nothing. Unfortunately, all my attempts have ...
0
votes
1answer
34 views
sed, getting an error: sed -e expression #1, char 28: unterminated `s' command
When I do:
sed 's/@driver.quit/#@driver.quit' set_QA_district_name_spec.rb
I get the error shown in the title.
How can I get around this error, what is wrong?
3
votes
2answers
79 views
sed pattern space and hold space
i was just going thorugh this and i was unable to understand.
sed -n '1h; 1!H; ${ g; s/foo\nbar/bla\nblub/ p }' file.
where cat file is :
foo
foo
bar
why there is 1!H because to me 1h ...
1
vote
2answers
41 views
Delete lines until a header with sed
I am incorporating SED into a Windows batch file. I've got it working for deleting the first seven lines of a text file:
SED "1,7d"
However, I'd like to make it a smarter statement. Essentially, ...
2
votes
3answers
125 views
How can I use SED or AWK to replace placeholders in a template file with variable content that contains special characters?
CentOS 6.3
I'm trying to get a small script to send an email containing a copy of email headers in the body (for the purpose of internal reporting).
The template file contains the following:
...
4
votes
3answers
104 views
Remove string from a particular field using awk/sed
I have a file (>80,000 lines) that looks likes this:
chr1 GTF2GFF chromosome 1 249213345 . . . ID=chr1;Name=chr1
chr1 GTF2GFF gene 11874 14408 . + . ...
1
vote
3answers
48 views
Does sed write to the file or give a sample output
when using sed with a file like this
sed 's/a/o' fruits
it gives the necessary output to the terminal but it does not change the contents in the file. How do I permanently change the file with the ...
0
votes
1answer
100 views
comparing lines with awk vs while read line
I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
1
vote
1answer
68 views
Coloring the output of conky-cli in dwm
I've recently installed conky-cli and got it running on the upper bar in dwm with this simple command:
conky | while read -r; do xsetroot -name "$REPLY"; done &
And I wanted to get colored ...
5
votes
5answers
207 views
How to remove multiple blank lines from a file?
I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
1
vote
2answers
125 views
Unix command for pattern matching
I want to count the number of words and print the matched pattern lines which matches exactly with following pattern:
abc-ERROR:
The input File contains:
# abc-ERROR: xyxxkkfgfr
# def-Error: ...
4
votes
4answers
103 views
How to remove character and space from a string
Hello I have one file with output
Name : ABC
Name : CDE
Name : ZYS
I want to get the result
ABC
CDE
ZYS
How can i get it through SED command.
I have tried. sed s/'Name' but ...
1
vote
2answers
37 views
Trimming one part if equal to another part?
I use an e-mail quote attribution string like this:
On dd mmm yyyy hh:mm +hhmm, from info@example.org (Example Dot Org):
where info@example.org is the sender's e-mail address and Example Dot Org is ...
9
votes
3answers
296 views
Deleting all C comments with sed
I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed, and this is what I have so far:
sed -i '/ * [^()] ...
0
votes
1answer
26 views
Comment the if statement and the matching endif keyword
In vim, I can find the matching if statement and prepend the appropriate comment symbol. (e.g. %s/.alarm./#\0/g), but then I am left with dangling endifs that I have to find manually. I could simplify ...
0
votes
2answers
87 views
Reordering strings in linux
How can I change lines around using the command line?
e.g. I have these lines:
Acct-Status-Type = Start
User-Name = "37XXXXXXX"
Event-Timestamp = "Apr 12 2013 15:56:55 AMT"
I need to ...
1
vote
1answer
68 views
Optimizing sed command or create new one
I'm a newbie in linux scripting, especially for using sed and awk commands.
For now I'm trying to filtering really big log file and wondering if there are any alternatives for my commands? or some ...
4
votes
3answers
145 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
55 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
35 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 ...
-8
votes
1answer
61 views
can anyone help me with this sed and grep? [closed]
(a) SED
Given a file, replace all the sequences of 4 or more digits with the
word "cat".
(b) GREP
Given a file, display all the lines starting with the word "cat" and
ending with the ...
2
votes
2answers
83 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 "#" ...
1
vote
1answer
46 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 ...
1
vote
1answer
87 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
50 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
62 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
110 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 ...
0
votes
1answer
32 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
87 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 ...
1
vote
2answers
158 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
3answers
82 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 ...
1
vote
3answers
174 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
50 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?
