Tagged Questions
Sed is a command-line stream editor for filtering and transforming text.
0
votes
0answers
22 views
Dynamic search and replace in Ksh
Machines at work follow a constant naming pattern:
host[domain]_[id]
where [domain] is either "d" for dev machines and "p" for production machines, and [id] is a 2-digit string that is different for ...
6
votes
1answer
77 views
How do you save a complex regex for multiple reuse in sed?
In using sed, I often create rather complicated and intricate regexes that I need to match twice in a file. Is there a way for me to save this regex and just reference it twice?
Maybe something that ...
3
votes
3answers
66 views
What does . match?
In working with regular expressions, I have been told that a dot character . will match everything.
Except for newlines \n.
Are there any other exceptions? What about the NUL character \0, or the ...
1
vote
2answers
66 views
Adding a line to the beginning of a file [closed]
Possible Duplicate:
Inserting text at the beginning of a file with sed via the terminal in Linux
I need to add a line to the beginning of a file. The line in question is
\def\submit{}
...
3
votes
2answers
89 views
Sed: Replace N first occurrences of a character
I am looking to replace the 5 first occurences of the whitespace character per line inside a sed script. Here's what I have so far
sed -e "s/ /;/" -e "s/ /;/" -e "s/ /;/" -e "s/ /;/" -e "s/ /;/" ...
3
votes
1answer
54 views
Cleanly swap all occurences of two strings using sed
Suppose I have a file that contains multiple occurrences of both StringA and StringB. I want to replace all occurrences of StringA with StringB, and (simultaneously) all occurrences of StringB with ...
3
votes
3answers
99 views
Inserting text at the beginning of a file with sed via the terminal in Linux [closed]
Possible Duplicate:
How can I prepend a tag to the beginning of several files?
How do I insert text at the beginning of a file via terminal?
2
votes
1answer
50 views
Substitute text with sed and keep part of the original text
I am trying to convert
<id>1</id>
<Name>ENTERPRISE RESOURCE PLANNING</Name>
to:
<column name="id">1</column>
<column name="Name">ENTERPRISE RESOURCE ...
2
votes
2answers
49 views
Stream error logs
I want to stream the contents of an error log (/log/spo.error) as it's written, but pipe the stream through sed before I see it. How can I do that?
3
votes
3answers
99 views
How do I grep without leading whitespaces?
I'm greping through a large codebase, and leading whitespaces and tabulation seem to be quite annoying. Is there any way to get rid of it?
grep -R "something" ./
E.g, instead of:
foo/bar.cpp: ...
4
votes
2answers
58 views
Replace string with contents of a file using sed
I have two different files:
File1
/home/user1/
/home/user2/bin
/home/user1/a/b/c
File2
<TEXT1>
<TEXT2>
I want to replace the <TEXT1> of File2 with the contents of File1 ...
1
vote
1answer
63 views
Make sed ask for confirmation before each replacement?
Is there a way to make sed ask me for confirmation before each replace? Something similar to 'c' when using replace inside vim.
Does sed do this at all?
2
votes
3answers
61 views
Using sed to edit lines in a file with a variable
I need to edit lines in a file using sed. Now the problem is I am replacing a particular pattern with a combination of text and number. This number is a variable which keeps on incrementing for every ...
3
votes
3answers
186 views
How do I delete all lines with “.png” in a file?
I've a list of urls of which some point to images:
http://s.thebrighttag.com/iframe?c=A5lqOqP
...
2
votes
1answer
60 views
How do I replace certain text with the respective line number using sed?
I have a file where certain (not all) lines look like so:
Sequence: n
I wish to replace n with the respective line number.
How can I do it with sed?