Sed is a command-line stream editor for filtering and transforming text.
4
votes
3answers
288 views
How to remove all white spaces just between brackets [] using bash? [duplicate]
Replace text between brackets
Input
testing on Linux [Remove white space] testing on Linux
Output
testing on Linux [Removewhitespace] testing on Linux
So, how can we just remove all the ...
8
votes
4answers
2k views
Efficient in-place header removing for large files using sed?
The commands below may takes minutes depends on the file size. Is there any more effient method?
sed -i 1d large_file
4
votes
2answers
77 views
Out of memory while using sed with multiline expressions on giant file
I am currently trying to remove all newlines that are not preceded by a closing parenthesis, so I came up with this expression:
sed -r -i -e ":a;N;$!ba;s/([^\)])\n/\1/g;d" reallyBigFile.log
It does ...
2
votes
2answers
58 views
sort a file based on length of the column/row
I need to sort a file based on the number of chars in the first column.
I have no idea on how to go about this. (On Linux, so sed/awk/sort is available).
An example:
.abs is bla bla 12
.abc is bla ...
2
votes
2answers
104 views
sed: replacing newline at a given line (or last line)
I have a file like the following:
a,b,c,d,e,f
1,2,3,4,5,6
7,8,9,0,1,2
I need to join the last two lines with a comma, like so:
a,b,c,d,e,f
1,2,3,4,5,6,7,8,9,0,1,2
The problem is that this is all ...
3
votes
2answers
85 views
How to convert *text* to {\i text} with sed?
I would like to replace every occurrence of *text* into {\i text}.
text *text* text
*text* text *text*
*text text text* text
should become
text {\i text} text
{\i text} text {\i text}
{\i text ...
1
vote
2answers
262 views
Help inserting a new line of text after matching a line of text (sed)?
I need to insert a hidden HTML input tag into any form tag within a bunch of HTML files. I assume this is possible with sed, but need help forming the command.
My idea is to search for any instance ...
3
votes
5answers
250 views
Remove lines based on pattern by keeping first n lines
I need to remove lines from a text file based on pattern but I need to keep the first n lines of that pattern.
Input
% 1
% 2
% 3
% 4
% 5
text1
text2
text3
output
%1
%2
text1
text2
text3
I used ...
0
votes
1answer
89 views
How to delete number of lines from file repetitively
I've read How do I delete the first n lines of an ascii file using shell commands?, it is helpful. However I've a file something as below (please consider 2 columns as 2 different files):
1 4
1 4
1 4
...
1
vote
3answers
73 views
sed replace - need help replacing text in bunch of files
How to parse bunch of files and replace each occurance of __esct function?
__esct('Full name')
convert to:
$this->escape($this->translate('Full name'))
I'm confused as to - how ...
1
vote
1answer
82 views
sed edit text block: not greedy match
I wish I can grab the first html comment in a file using sed.
Using '/<!--/,/-->/ and having more than one comment block it will match all the content between the first and the last comment ...
2
votes
1answer
55 views
Extract code excerts from markdown file
I have a pandoc markdown file which has a lot of code. I want to extract all the code bits from file preferably using sed. The syntax of code in pandoc is three or more ` signs to start and finish the ...
3
votes
4answers
920 views
removing the first and the last character of every line from command line
I am trying to remove the first and the last characters of everyline in a text file and save the resulting truncated version in a new file. Does anyone have an idea about how to do that efficiently ...
3
votes
2answers
506 views
Insert a multiline string into another string
I need to insert lines into an xml file :
Insert
<one>
</one>
into
<tags>
</tags>
To obtain
<tags>
<one>
</one>
</tags>
I tried this:
...
0
votes
2answers
369 views
Replace matches with multiline string using sed [duplicate]
Possible Duplicate:
Insert a multiline string into another string
I have a file called foo.txt containing:
foo
bar
baz
I want to replace every occurence of bar with a multiline string, ...
1
vote
3answers
260 views
linux/solaris + verify duplicate valid IP address from file
what the best way to find duplicate IP from file ( I have ksh script in this script I need to write function that check for duplicate IP )
for example if IP - 192.1926.23.52 exists twice in file - ...
3
votes
2answers
624 views
sed: multi-line replace of config block
I have some configuration files that basically look like
(...content...)
# BEGIN DYNAMIC BLOCK - DO NOT EDIT MANUALLY
(... more content ...)
# END DYNAMIC BLOCK
(... even more content ...)
Now, in ...
0
votes
1answer
158 views
wget images with certain path
im looking to only grab images from a document with a certain path for example
domain.com/uploads/287167/file_name.jpg
only grab those with the uploads/number/filename
im currently doing it this ...
3
votes
5answers
158 views
Print non-existent files from a pipe input
I have a directory of lots of .PDF and .JPG files.
There should be a .JPG file for each .PDF with the same name.
I'm trying to use a command to find .PDF files that doesn't have a .JPG file.
My ...
5
votes
3answers
831 views
Sed to reverse two words
echo "AXIS2C_HOME=/usr/local/Axis2C" | sed 's/\(^AXIS2C_HOME=\) \(.*\)/ \2 \1/'
The output I am expecting is /usr/local/Axis2C AXIS2C_HOME=.
I can't figure out what I am doing wrong. :(
1
vote
1answer
154 views
Sed and Awk learning material [closed]
I'm looking for some learning material for sed and awk, can anyone make any suggestions?
Please don’t refer to man and help pages.
-O-
1
vote
1answer
81 views
how to add a description in footer
I enjoy learning how to modify files with awk, sed, and bash. However, I know it could cause issues down the road and I would like to be prepared with a log inside the file. I was thinking about how ...
1
vote
5answers
207 views
Replacing lines in files with file contents
I have several files which contain some PHP includes and I want to substitute them with the file contents. The file looks like
foo
<?php
include("file1.php");
?>
bar
baz
<?php
...
0
votes
1answer
176 views
globbing, sed, or awk html files
I wanted to create a script that I could check .xhtml files for images and add alt tags if needed. While searching I found regular expressions and did man on glob but I'm unsure on where or what to ...
0
votes
3answers
220 views
Split and print
I have tab-demlimted text file with 50,000lines. I want to split the first column and print as shown in output.txt
Input.txt
rt|371443144|mb|MN556661.1| 2200443 A
rt|371443344|mb|MN556645.1| ...
2
votes
2answers
255 views
extract last match from logfile till end
Using sed, grep, awk, or ruby, what's a simple way to find the last match of a string in a larger log file, and send every line following it (inclusive) to another file?
Example:
grep -A222 ...
2
votes
1answer
357 views
Using a here-doc for `sed` and a file
The title says it all, I want to use a here-doc for sed commands and provide the file to be read and the output file.
I've looked at Here-Documents from Advanced Bash Scripting guide but it does not ...
0
votes
1answer
388 views
Linux + replace STRING/WORD in file according to rule
My target is to replace any word/string/Any characters in file
with new word/string according to the following rules:
If numeric characters on the left side of word/string then we not replace the ...
1
vote
4answers
395 views
How to rename files with sed and csv
I'm new with Linux, sed, and awk but I don't mind challenging myself on new ideas. That being said, I understand the purpose and how to use rename and sed for a common event such as adding a $date or ...
1
vote
3answers
178 views
Script matching literal pattern over multiple lines?
I have a multi-line string in the variable $PAT. $PAT must be searched for within the file $FILE. If $PAT is in $FILE, it needs to print the file with $PAT removed. If $PAT is not found, then print ...
0
votes
4answers
202 views
Sed regex - include original matching
INPUT:
dsfgsdf8gfsd
2011.06.26. v
iudsfg98sdfg
sosdufgsdfg
2011.06.27. h
8xdofguiosdfg
jdasfhasd89fa
2011.06.28. k
ydsfgsdgsdg
dsfgdsfzfszgh
2011.06.29. sze
ds9fgisdfgsdfg
asdfasdfasddf
2011.06.30. ...
1
vote
1answer
84 views
Display words in color
I am looking for a tool which takes a file in input and a word to search. It should display the file with color the words if it corresponds to the search.
Like grep --colors but displays all the ...
3
votes
2answers
152 views
Colorizing tail output with sed
How would I go about colorizing the output of tail with sed?
echo "`tput setaf 1`foo`tput op`" works as expected
echo "foo" | sed -e 's/(foo)/`tput setaf 1`\0`tput op`/g' however, does not.
What am ...
10
votes
4answers
10k views
How to manipulate a CSV file with sed or awk?
How can I do the following to a CSV file using sed or awk?
Delete a column
Duplicate a column
Move a column
I have a big table with over 200 rows, and I'm not that familiar with sed.
1
vote
4answers
515 views
Remove newline from unix variable
I have a variable whose value is found using sql query.
I want to remove the new line charcater from that variable since I want to concatenate this variable with the other. Below is the code:
...
3
votes
5answers
124 views
grep device name and look for next value :
I have this output from a find command:
abc,10.11.13.14,def,1.2.3.4,geh,6.7.54.23
where abc,def and geh are device names and could be of any length and others are IP address belong to devices. ...
7
votes
10answers
505 views
What's a good way to filter a text file to remove empty lines?
I have a .csv file (on a mac) that has a bunch of empty lines, e.g.:
"1", "2", "lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum ...
1
vote
2answers
135 views
How can I find matches with sed (or similar) for configuration parameters?
I'm pretty good at using php's preg_match (and similar) commands, and I'm also pretty good with regular expressions, but I don't do very well with sed.
I have two shell scripts I'm working on and I'd ...
1
vote
2answers
220 views
Deleting specific lines and duplicates from a 11gb wordlist text file
I have an 11gb wordlist file which is already sorted as each word is on its own line.
I need to remove duplicates and lines starting from 077.
I guess I need to run sed and sort -u together but I ...
0
votes
1answer
66 views
Sort Column with matching string
I have tab-demlimted file, I want to sort them only for red_ball as follows
input.txt
id tagid name
HH556 EN76 red_ball
JH678 EN45 green_ball
MH678 CV67 red_ball
TY896 ...
2
votes
4answers
2k views
How can I find and replace with a new line?
I have a CSV delimited by commas and I want to delimit it by newlines instead.
Input:
a, b, c
Output:
a
b
c
I've written Java parsers that do this stuff, but couldn't this be done with vim or ...
1
vote
1answer
180 views
Diff, show modified line from right file only
I have file a and b and I would like to output lines of b that changed since it was cloned from a. Just the modified lines, no surrounding context, no diff offset marks.
How can I do that using shell ...
3
votes
2answers
78 views
Replace matched file path with contents of file at the path with sed
I want to write a short deployment script which enters the contents of javascript-files into the single html file. These js files are currently declared as:
<script ...
1
vote
4answers
900 views
How to print all lines after a match up to the end of the file?
Input file1 is:
dog 123 4335
cat 13123 23424
deer 2131 213132
bear 2313 21313
I give the match the pattern from in other file ( like dog 123 4335 from file2).
I match the pattern of the line ...
9
votes
4answers
1k views
Delete last line from the file
I use sed to quickly delete lines with specific position as
sed '1d'
sed '5d'
But, what if I want to delete the last line of the file and I don't know the count of lines (I know I can get that ...
6
votes
3answers
648 views
Replacing Multiple blank lines with a single blank line in vim / sed
Question more or less says it all. I'm aware that /^$/d will remove all blank lines, but I can't see how to say 'replace two or more blank lines with a single blank line'
Any ideas?
3
votes
2answers
142 views
Extract lines containing PAT1 but not PAT2 with sed
I want to extract the lines containing PAT1 but not PAT2 from a file. For example, with PAT1='dog', PAT2='cat', and the following input:
1 cat chicken
2 bird dog apple
3 dog orange cat
4 cat juice ...
6
votes
4answers
2k views
Remove line containing certain string and the following line
I use this
cat foo.txt | sed '/bar/d'
to remove lines containing the string 'bar' in the file.
I would like however to remove those lines and the line directly after it. Preferably in sed, awk or ...
2
votes
4answers
311 views
Replace all but a set of characters in a file with newline
how to delete all characters in file except numbers and "." ,
each word (numbers/dot) should be in new line in file see example2
the solution can be with sed or awk or ksh syntax
remark - ...
2
votes
2answers
360 views
Removing Color Codes From Output [duplicate]
Possible Duplicate:
Removing control chars (including console codes / colours) from script output
I'm working on a script to work alongside a program that I'm writing. What i'm trying to do ...


