Sed is a command-line stream editor for filtering and transforming text.

learn more… | top users | synonyms

1
vote
2answers
329 views

iterate through files ('for file in…) and also include sub directories?

I am using sed to do a bunch of changes to files. I think the question is relevant for any operation that want to iterate through files that match a pattern and include subdirectories both in the ...
1
vote
1answer
147 views

best programming language for I/O intensive tasks [closed]

I need to process "big data" (nearly 1TB which can be partitioned into smaller chunks). Consider several programming languages (Java, Python, C++, Perl) and other scripting options (Perl, awk, sed, ...
4
votes
1answer
201 views

Matching Five Columns in two Files using Awk

I have two Input files. File1: s2/80 20 . A T 86 F=5;U=4 s2/20 10 . G T 90 F=5;U=4 s2/90 60 . C G 30 ...
4
votes
1answer
192 views

Reverse a line in sed?

echo 1234 | sed ' /\n/ !G s/\(.\)\(.*\n\)/&\2\1/ //D s/.// ' I'm unable to comprehend the above sed code. my understanding is: PATTERN SPACE=1234 first ...
1
vote
2answers
153 views

Replace a pattern which ends at newline with the same pattern without the newline

I have a javascript file with two new lines after a particular word "[FACT]", I want to replace it with one newline. I need to do it in bash script. Normally, I would have used sed but it turns out ...
4
votes
1answer
89 views

Is strace a suitable tool for finding out where a program wrote to the filesystem?

I'd like to determine where a certain app (as an example, surf) writes to the filesystem in order to make sure it leaves no traces. Without a dedicated sandboxing system this probably isn't easy, but ...
4
votes
1answer
5k views

Using sed to extract text between 2 tags

I have a .xml file and I'm trying to do a "groupinstall" on a RHEL6 machine as there are several hundred libraries in that .xml file... (close to 16 000 lines). I'm therefore trying to extract the ...
3
votes
3answers
83 views

Using sed (?) to extract one instance of a string that is repeated in the original string

INPUT: <a href=FII/FOO./>FOO</a> OUTPUT: FOO Q: how can I replace the INPUT with the OUTPUT? The FII and "./>" is CONSTANT. The FOO could vary to any english letter and "-" and "." ...
2
votes
2answers
217 views

sed - remove unmatched “}”, “)” or ']" (only for the line in question)

I have a file with a lot of lines Some of the lines end in unmatched braces, i.e. "}" This is only true for lines that contain ".to" How can I remove the unmatched braces with sed for ALL lines ...
4
votes
3answers
1k views

using sed to replace pattern with hash values

I want to search the file and replace specific pattern with its hash (SHA1) values. For example, let file.txt has the following content: one S56G one two three four five V67X six and I want to ...
2
votes
3answers
151 views

sed - how to do several consecutive substitutions but process file only once?

If I am doing several substitutions which need to be consecutive, e.g. sed -i '/^[[:space:]]*browser.*\.should/s/browser/expect(browser/' t1_spec.rb sed -i ...
0
votes
3answers
152 views

sed - change lines that start with one given word and end with another?

For example, given: $ cat test001.txt this is a test bucket bucket line not this one. bucket lein endy bucket and others endy and a ttest How can I change the lines that start with "bucket" ...
3
votes
4answers
480 views

How to Prefix a column values with an apostrophe ( ' )?

I have a CSV file with multiple columns and 1000's of records, I need to prefix all the values of one of the columns (lets say 2nd column) with an apostrophe ' except in the first line or header line, ...
6
votes
2answers
387 views

How to report “sed” in-place changes

When using sed to replace strings in-place, is there a way to make it report the changes it does (without relying on a diff of old and new files)? For instance, how can I change the command line ...
5
votes
3answers
5k views

Filter a .CSV file based on the 5th column values of a file and print those records into a new file

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , ...
8
votes
6answers
898 views

How to get multiple lines out of a file by a regex?

How to get multiple lines out of a file by a regex? I often would like to get multiple lines / modify multiple lines by a regex. A example case: I am trying to read part of an XML/SGML file (they ...
4
votes
5answers
624 views

Multi-line grep beween two tags, only show the last match

I'm having a program that intermingles data segments into log output: log message log message ----BEGIN INLINE DATA---- data data data -----END INLINE DATA----- log messge I'm looking for something ...
0
votes
0answers
26 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
10
votes
5answers
19k views

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
0
votes
3answers
166 views

Search in iptables.log file takes a long time

I have used iptables to save information about connections by modifying the /etc/syslog.conf file to save information in /var/log/iptables.log. So, every X hours, I need to extract information from ...
1
vote
4answers
4k views

How exactly do I create a sed script and use it to edit a file? [duplicate]

I know how to edit a file using sed one step at a time, but how would I create an actual sed script and then use it on the file to do the same things that the individual sed commands would do? For ...
1
vote
2answers
154 views

How would I use sed to detect a certain amount of numbers before it inserts a character? ###-###-####

I need to format phone numbers in a text file. They appear as (example) 8014516912 How would I format it so that I can insert a - after the first 3 numbers, and then another - after another 3 ...
2
votes
1answer
958 views

How would I use sed to insert a character at a certain character position on only ONE line?

I am aware that this will do what I want on all lines: sed 's/^\(.\{4\}\)/\1-/' textFile But how would I enter a - after the 4th character slot on ONLY the 5th line? Or even better, on a range of ...
3
votes
2answers
2k views

How can I get my sed command to make permanent changes to a file?

Is this possible? I read somewhere that the following command would do it: sed -e [command] [file] but it appeared to do the same thing as just sed [command] [file] (it did not save the ...
3
votes
2answers
1k views

Replace a pattern in a file with a long string

I'm writing a little shell script to generate a directory listing. To make the output easily customizable, the script just builds a HTML-table and than should replace a specific token in a template ...
5
votes
3answers
545 views

Deleting Lines if there is a dot in the 5th Column

I have a file and I want to remove all the line if it has a dot in the 5th Column. Input File: sc2/80 20 . A C 80 PASS N=2 F=5;U=4 sc2/60 ...
0
votes
2answers
6k views

Removing text between two specific strings

I have a file as below: mime PI Name: ISHO SUCCESS RATE RT, Value: 95.663826 scr PI Name: RRC Access Failures due to UU, Value: 0.13394141 prog PI Name: RRC Access Failures due to UU, Value: ...
2
votes
1answer
173 views

How to extract single value from single line tuples?

I have a dump file of a database in the following form ('value1','value2',value3','value4'),('value1','value2',value3','value4'),... I want first to have each tuple in a single line and next i ...
0
votes
1answer
77 views

Can i use & variable of sed for doing operation inside $()? [duplicate]

I am not sure whether the below statement can be done placing & inside $() so that each time & is replaced by 1,2,3,4 and 1 is added to it. echo 1 2 3 4 | tr ' ' '\n' | sed "s/.*/$(echo expr ...
3
votes
1answer
521 views

Efficient way to print lines from a massive file using awk, sed, or something else? [duplicate]

If I had a plain-text file containing 8 million lines and I want to print out lines 4,000,010 to 4,000,000 to the screen, which would be more efficient: awk or sed? There is no pattern to the text, ...
0
votes
2answers
265 views

any command that can format html or xml from shell? [closed]

There must be something on the lines of sed? Normally in sed you type something like: echo day | sed s/day/night/ the shell prints "night". Is there something that can take a file (containing ...
0
votes
4answers
62 views

cut+sed function joined

Input dir/foo Output dir./ so I need: echo 'dir/foo' | MAGIC Q: What is MAGIC? (something like a cut+sed joined:D)
3
votes
2answers
684 views

sed: match two lines

I have a text file, where records are split on two lines. I would like to put them on one line. The records look something like this: 2013-07-29 apt-get install git 2013-07-29 apt-get install rsync ...
3
votes
3answers
1k views

Count the number of rows in each column of a text file

I have a text file with the following format: 5 3 1 2 3 4 ..... ..... i.e. space separated 3 columns of numbers/ However, some of the rows may be like: 2 3 1 So, I want to detect if the text file has ...
1
vote
3answers
278 views

Reversing the value key pairs of array using sed or pattern replacement or brace expansion?

#!/bin/bash arr=(a b c d) declare -A brr for i in ${!arr[@]} do brr[${arr[$i]}]=$i done echo ${brr[@]} #0 1 2 3 Is there any way to reverse the values and key pairs ...
2
votes
1answer
3k views

How to assign result of sed to variable

Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces. Once this is done, I want to ...
1
vote
1answer
280 views

How to use awk or sed to convert csv diffs into more readable format

Can anyone give me the example of how to use awk or sed (not sure which one, as I haven't use either of these much, as I have mostly been using grep and cut to work with csv data) to convert ...
2
votes
3answers
2k views

Printing match groups with grep

I have the following grep: grep -Po 'href="(http://.*)">Transcript.* - ([0-9]*)\. (.*)</a>' I would like to print out the match groups. Is there a way to do this without Perl/Python? I ...
2
votes
2answers
175 views

Sanitize Apache access log files?

We have this code in a shell script that pipes output for Apache to log. declare -a values=( $taintRequestVals ) for item in ${!values[@]} do cat $apacheLog | sed ...
2
votes
1answer
52 views

How can i change the format of text using sed?

cat > inputfile X1 a1,b1,c1,d1.................. dn X2 a2,b2,c2,d2.................. and so on upto n ................................................ ...
12
votes
8answers
2k views

How to perform a multi line grep

How would you perform a grep for text that appears on two lines? For example: pbsnodes is a command I use that returns the utilization of a linux cluster root$ pbsnodes node1 state = free ...
13
votes
6answers
893 views

How to achieve portability with sed -i (in-place editing)?

I'm writing shell scripts for my server, which is a shared hosting running FreeBSD. I also want to be able to test them locally, on my PC running Linux. Hence, I'm trying to write them in a portable ...
3
votes
2answers
246 views

Join: Two files - but only append last two columns

Given the files: 1.txt 1, abc, 123, 456, 789 2, lmn, 123, 456, 789 3, pqr, 123, 456, 789 2.txt 1, abc, 123, 000, 000 3, lmn, 123, 000, 000 9, opq, 123, 000, 000 OUTPUT.txt ID, NAME, X, ...
5
votes
2answers
3k views

Single command taking two strings to extract string between them, like 'tr' (without expressions)

Saw here a way to use sed to get text between two other strings in a line, like: sed 's/.*starting_text\(.*\)ending_text.*/\1/' but I'd like a simple command (like tr, but for string extraction) ...
3
votes
3answers
322 views

Join every other column with sed or awk

I have a large text file (666000 colums) in the format A B C D E F Desired output AB CD EF How can we do it in sed or awk. I have tried a couple of things but nothing seems to be working. Please ...
6
votes
5answers
255 views

Get filesystem name and usage with `df -h`

df -h | grep test | sed -e 's/*%.^ //g;s/.*[ ^I]//' Output: /test /test/drv0 /test/drv1 df -h | grep test | cut -d '%' -f1 | sed -e 's/*%.^ //g;s/.*[ ^I]//' Output: 10 20 15 I want to ...
3
votes
1answer
3k views

Get all regex matches between two patterns and print them to file

I've got a file with a bunch of long lines. I'd like to grab every group between two patterns and print them to a new file, one match per line. I could manage to do this with Python, but I'd prefer ...
0
votes
2answers
781 views

How to remove n number of lines from a file using sed command? [duplicate]

I want to remove a particular number of lines after the given pattern is matched. Can anyone please tell me how that can be done using the sed command ?
2
votes
4answers
222 views

AWK Search massive file and write to variable name

I want to pull data that I will need to reformat from a simulation file I am working with to prepare it as input for running other simulations. The target data is an optimized chemical z-matrix. The ...
0
votes
1answer
478 views

Sed - unknown option to `s'

I execute a sed command in my script: sed -i "${1}s/${2}=.*/${2}=${REPLY}/" $3 this is the echo: sed -i 13s/log4j.appender.ROOT2.File=.*/log4j.appender.ROOT2.File=/app/TET/log.log/ ...