Sed is a command-line stream editor for filtering and transforming text.
1
vote
3answers
564 views
bash merge 2 lists removing duplicated
I have an embedded linux system using Busybox (OpenWRT) - so commands are limited. I have two files that look like:
first file
aaaaaa
bbbbbb
cccccc
mmmmmm
nnnnnn
second file
mmmmmm
nnnnnn
...
2
votes
3answers
407 views
Average rows with same first column
Given a file with two columns:
Id ht
510 69
510 67
510 65
5l0 62
510 59
601 29
601 26
601 21
601 20
I need a way to coalesce all rows with the same ID into one that has an average height. In this ...
3
votes
6answers
173 views
Extracting help message from script itself
I want that my help message be extracted from the script itself.
#!/bin/bash
#
# foo - do things
# Author: John Doe <jhon@doe>
# ----------------------------------------------
# SYNOPSIS
# ...
1
vote
2answers
160 views
Substitute pattern within a file with the content of other file
I have a text file (devel.xml).
I added the word REPLACETHIS to it in order to replace this string with the content within a different file (temp.txt).
The closest thing I have is this:
sed -i -e ...
4
votes
2answers
259 views
Passing parsed output of sed to find (in this direction)
Well, I think you can find dozens of questions on this platform how to pipe find output to sed, but I haven't found anything for the reverse direction so far. What I want to do is modify my input, and ...
2
votes
1answer
282 views
Inserting a file into another file using sed
I want to insert the contents of file1 into file2 after a matching PATTERN. I want to do it only after the first occurrence of the PATTERN.
I would like to know the modification I need to make to ...
2
votes
3answers
1k views
Extracting column from comma separated text
I have a long comma-separated delimited file with 20K lines. Here's a sample:
"","id","number1","number2","number3","number4","number5","number6","number7"
...
7
votes
5answers
2k views
Remove comma between the quotes only in a comma delimited file
I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row
123,"ABC, DEV 23",345,534.202,NAME
I need to ...
2
votes
2answers
560 views
Replace the shortest match of a string pattern
I have this string:
update mytable set mycol=myvalue where mycol=yourvalue;
I need to convert it to:
insert into mytemp select * from mytable where mycol=youvalue;
I can accomplish it like this ...
4
votes
3answers
223 views
Want to search for two consecutive lines with at least n characters
I would like to use sed to search for the first part of a text file with consecutive lines with at least n non-space characters. I would like to print from the first of those lines to the end of the ...
4
votes
1answer
436 views
How is this sed command working?
I want to understand, how following sed command is working:
sed -nre "/jar$/ { x; d; }; /class$/ { x; p; }
Actually it is part of another command to find a particular class file from the given list ...
5
votes
3answers
377 views
How to embed a shell command into a sed expression?
I have a text file with the following format:
keyword value
keyword value
...
Where keyword is a single word and value is everything else until the end of line. I want to read the file from a shell ...
1
vote
2answers
308 views
Parsing the output of date with sed
I am trying to replace the whitespaces in the output of date with '_' with no success.
$date
Fri Sep 14 14:10:04 EDT 2012
$ date | sed 's/ /_/'
Fri_Sep 14 14:10:24 EDT 2012
As you can see, the ...
2
votes
1answer
223 views
Using sed, how can I replace a line containing a pattern with contents from another file?
input_file.txt:
one fffds
two xxxx
three ffff
four ffde
data_file.txt:
six
seven
I want to replace the line containing two xxxx in input_file.txt with the content of data_file.txt. The output ...
3
votes
4answers
2k views
How to get all lines between first and last occurrences of patterns?
How can I trim a file (well input stream) so that I only get the lines ranging from the first occurrence of pattern foo to the last occurrence of pattern bar?
For instance consider the following ...
2
votes
3answers
286 views
with sed, how can I replace word within a matching line?
I am trying to write a sed expression to detect lines similer to this:
s0:12345:respawn:/sbin/agetty -8 -s 115200 ttyS0 linux
and replace the "ttys0" with "something_else"
I do not want to detect ...
2
votes
2answers
183 views
Piping paths with different types of quotes for slash substitution
I would like to use sed to convert a path with backslashes to the same path with forward slashes:
E.g.
I would like to pipe \\path\to\file\ and obtain /path/to/file
None of the following commands ...
4
votes
4answers
993 views
Concatenate lines by first column (AWK or SED)
How can I use AWK in the following situation?
I want to concatenate lines that start with the same column. Only the first column is kept after the join (in this case aaa, www, hhh).
The file may be ...
0
votes
5answers
1k views
compare two files get identical list
file1.txt (50 lines)
TERYUFV00000010753
TERYUFV00000009526
file2.txt (500 lines)
TERYUFV00000009526 refids_739_known_8/10_target
TERYUFV00000018907 refids_12023_known_21/22_target
...
3
votes
2answers
343 views
What is the best way to find a list of several strings within a large text file
The short, general question is: In Unix/Linux, what is the best way to find a list of several (about 150) strings within a large text file?
I am asking this to all Unix/Linux experts as a general ...
4
votes
3answers
222 views
sed convert 4 spaces to 2
How does one convert 4 spaces into 2 spaces with sed? Is it possible?
I found this but it converts tab to spaces:
sed -r ':f; s|^(\t*)\s{4}|\1\t|g; t f' file
2
votes
3answers
81 views
Need to parse a double entry table with two pairs
I have this two-entry table resulting from a program output:
Variable1 : Value1
Variable2 : Value2
Variable3 : Value3
Variable4 : Value4
Variable5 : Value5
Variable6 : Value6
...
2
votes
1answer
413 views
update PATH variable in .bashrc using sed
I've been trying to update my PATH variable permanently by putting it in my .bashrc file. However, I don't want to just append it to the file, but rather replace the current PATH=........ with the ...
1
vote
3answers
555 views
How to rename files using sed?
This is an sed expression that was created by a contributor here. More specifically by @craig-sanders.
$FileToMove is set to "2012-09-01 Home insurance quote_zz20.pdf"
# use sed to extract folder ...
0
votes
2answers
169 views
Getting data from matching list
list.txt
GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
GETID_9248_knownids_6/10_Confidence_0.439_Length_2474
GETID_11084_knownids_3/3_Confidence_0.600_Length_1451
...
1
vote
3answers
1k views
sed/awk/perl - delete spaces between two strings/words + solaris 10
please advice how to delete the spaces between "=" to the value/string ( after the "=" character) , should be implemented by awk or sed or perl command and command must to fit for solaris OS , ( ...
0
votes
5answers
2k views
(Mac Terminal) sed to parse JSON … what am I doing wrong?
In Mac Terminal, I'm trying to parse the "name" out of this JSON response:
{"created_at":"2012-08-27T20:04:27Z","deleted_at":null,"id":21462840,"item_type":"video","name":"CastingBy-v12
...
5
votes
7answers
251 views
Swapping an unlimited number of columns
I have a file with columns. See below for an example:
a b c ... z
1 2 3 ... 26
I'd like to swap all columns where the 1st becomes the last, the second becomes the one before last...etc..
z y x ...
3
votes
2answers
100 views
Column mismatch and substituting
input.txt (tab-delimted)
TTTTOTTT00000000008 RTTTT899 5.00E-28
TTTTOTTT00000000046 RTTTWRR 3.00E-31
TTTTOTTT00000000051 2.00E-11
TTTTOTTT00000000051 7.00E-12
TTTTOTTT00000000054 ...
1
vote
1answer
69 views
Match slash in bbe
How can I match a forward slash in bbe?
If I have this text file called test.txt:
foo / bar
I can match it in sed like so:
sed -e 's/foo \/ bar/it worked!/' test.txt
However when doing the same ...
1
vote
1answer
259 views
Delete specific line number(s) from a text file using sed?
I want to delete one or more specific line numbers from a file. How would I do this using sed?
6
votes
2answers
639 views
Using sed to color the output from a command on solaris
I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10).
Command ...
3
votes
2answers
283 views
merging two column
input_file (columns are tab delimited, only column 4 contains spaces)
input
A B C D;<>X;<>Y 0
C D E F;<>Z;<>X 1
output
A B C D;<>X;<>Y;<>apple=0
C D ...
2
votes
1answer
364 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
159 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 ...
2
votes
1answer
948 views
Delete last character in a word but only if the character is there - in bash
How to remove last character only if it's there?
input:
OpenOffice.org/m
openOffice.org/ozm
Pers.
Pfg.
phil.
Prof.
resp.
Roonstr./m
roonstr./ozm
desired output:
OpenOffice.org
openOffice.org
...
2
votes
2answers
133 views
How to Wrap a file with Tags in Bash
I have an xml file named test.xml, without a root tag like this:
<cat></cat>
<name></name>
<id></id>
<cat></cat>
<name></name>
...
1
vote
4answers
770 views
Appending a string containing escape character with sed
Currently I use:
sed -i -e "5a\\
${text}" $filename
to append something to a certain line, where the variable text
contains a string such as "\epsilon".
When using
echo -E $text
the string is ...
5
votes
3answers
302 views
Gedit or an other non-commandline editor with the ability to spell-check two languages at the same time
I'm searching for an editor with the ability to spell-check two languages at the same time (German and English). Gedit can't do it out of the box.
But I want to use Gedit. It should be possible by ...
2
votes
2answers
189 views
Get row data for non-matching column values
I want to read the file (1600 rows) and get rows only the columns have different values (sno1, sno2, sno3 & sno4-should be not be equal value) and it should be above
50%.The example of output ...
4
votes
3answers
1k views
How to get only filename using sed
How can I get only the filename using sed? I've this
out_file=$(echo $in_file|sed "s/\(.*\.\).*/\1mp4/g")
But I get the path too /root/video.mp4, and I want only video.mp4.
3
votes
2answers
171 views
Print row contain maximum and minimum value
I need to read the file (contains 16K rows)and print the entire row if any of columns and all columns contains max value (100) and all columns contain min value (0).The ouput example is given
...
3
votes
5answers
478 views
extract fields from “tail -f” of a syslog stream
Example line from syslog file:
Aug 1 10:25:50 10.10.10.1 id=firewall sn=XXXX time="2012-08-01 14:35:18 UTC" fw=x.x.x.x pri=6 c=1024 m=537 msg="Connection Closed" f=11 n=195273698 ...
2
votes
3answers
3k views
Sed : Replace pattern on every second occurence?
Is there a way to tell sed to replace the pattern on every second occurrence? Or at least on every second line? (Sure it's possible with a script, but I was asking myself if sed can do it to).
...
2
votes
1answer
153 views
Oneliner to detect camelcase variables
I would like to insert some style tests as git hooks in order to stick with precise style rules.
How can I come up with a oneliner that detects and prints arbitrary camelcase variables like the ...
4
votes
3answers
205 views
Print a line only if the next line does NOT contain a particular match
I am trying to search a log file for logged activities that did not complete. For example, I log a "Starting activity for ID 1234..." and if successful, the next line will be "Activity 1234 ...
1
vote
2answers
143 views
Matching values within columns
I have tab-delimited text file containing about more than 1500 rows.
input.txt
id sno1
EN1 Nucus_2158_mri_1/2_Co_1.0_Le_3104
EN2 Nucus_2158_mri_4/2_Co_1.0_Le_3104
EN3 ...
3
votes
2answers
1k views
Working with columns - awk and sed
I am trying to parse a text file that is generated by an expec script that
pulls down some information from a switch.
Here is a sample output:
192 0000.0000.0000 1/g23 Dynamic ...
1
vote
2answers
98 views
Can sed be used to generate a load file for my date lookup fact table?
I have an SQL fact table which is used for looking up a date and returning another date.
The table schema is as follows:
TABLE date_lookup
(
pk_date DATE,
plus1_months DATE,
plus2_months DATE,
...
2
votes
1answer
524 views
Only return the matched string in sed [duplicate]
Possible Duplicate:
Extracting a regex matched with 'sed' without printing the surrounding characters
How do I make this only print test:
echo "atestb" | sed -n 's/\(test\)/\1/p'
