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

learn more… | top users | synonyms

2
votes
3answers
57 views

Sed - string substitution with groupings

I have a largish directory with filenames formatted like Some_Folder-(FOL001)-clean what I'm trying to do is display the pattern between the brackets at the start like FOL001 ...
2
votes
3answers
97 views

Free BSD/ Mac OS X Sed: Print regex match and the line 5 lines after the match

I thought it would be sed -n /mymatch/,+5p but I get expected context address. At this point I am just guessing commands, nothing works! I want to grab every line that matches the regex and print ...
0
votes
3answers
49 views

Replacing multiline consecutive tags with a single line using sed and ignoring white spaces

I have a large XML file with several tags. One of the sub tag is as below: <Products> <SubProduct> ----> this line is problem <SubProduct> ...
1
vote
3answers
261 views

Remove whitespace and parentheses in filenames with sed [duplicate]

I'm an absolute newbie in the unix area so forgive me off the bat if I've gone about this the wrong way. I have a series of files I need to rename which all have the pattern " (*)" in them. Eg; ...
0
votes
2answers
48 views

Turning percentages into decimals?

I've got a CSV file that has percentages here and there expressed in text format, e.g. 173.91,0.00%,36.10%,1.71 Question of the day is how do I turn that example into 173.91,0,0.3610,1.71 Edit ...
3
votes
1answer
84 views

Can someone clarify this Bash script

I'm learning something about Bash scripting, and I came across this example: The task is to write a Bash script that reads a file, given with the first argument, pulls out those records that have the ...
4
votes
2answers
60 views

Why sed prints first string from file even if it's failed to find matching groups

I'm trying to write sed expression which will extract matching groups from file. E.g. I have .cue sheet and I want to extract it's genre tag. It has following format: $ cat file.cue | grep GENRE REM ...
1
vote
2answers
41 views

Escaping blackslash in sed

I am trying to write a sed command to replace a line in a file. The sed replace required the current working directory, which starts making the command a bit messy because of the characters that need ...
4
votes
2answers
70 views

Cut a string- Catch: There is file with same name as string in the same path

Input /in/archive/ABC/20140111_ABC_018_PART_001.dat Desired Output: 20140111_ABC_018_PART_001.dat Command used: cut -d/ -f4 "/1a/ftproot/archive/ABC/20140111_PR1_018_SALESDOC_ITEM_001.dat" ...
0
votes
2answers
63 views

Print 2nd and 7th lines to a file using `sed`

I have a directory of .txt files. For each, i'd like to grab the 2nd and 7th line, and add those lines to another file, which I've arbitrarily named list.index. I'm not sure how to tell sed about the ...
1
vote
3answers
61 views

Extracting n characters from a test line

How can I extract the 6 characters after Z in the following text line and put it into a file using grep, egrep, sed or awk? ...
1
vote
1answer
82 views

Parsing csv with sed and perl one-liner?

I have a web server which stores configurations to PostgreSQL, and I plan to retrieve information from a certain table and then later parse it into csv format. PAYLOAD <?xml version="1.0" ...
1
vote
1answer
50 views

Processing FreeBSD's PF logs with tcpdump/sed/awk

I'm running FreeBSD and have PF firewall set up and this is command i use to display daily number of firewall hits (blocked traffic) sudo tcpdump -n -e -tttt -r /var/log/pflog | grep $(date ...
1
vote
2answers
51 views

Printing and deleting the first line of a file using `sed`

I can print the first line of a file using sed -n 1p file.txt I can delete the first line of a file using sed -i 1d file.txt Is there a way to print-and-delete in sed? Kind of like a FIFO pop() ...
1
vote
4answers
65 views

Print the string between two parentheses

I have file with these lines G8 = P(G1,G3) G9 = P(G3,G4) G12 = P(G2,G9) G15 = P(G9,G5) G16 = P(G8,G12) G17 = P(G12,G15) I need the output as G1,G3 G3,G4 ..... How can I do it with sed/grep ...
1
vote
2answers
55 views

Mailing out a customised content based on specific search in a logfile

Using below test.sh, I am getting result in dump.txt as below: test.sh: #!/bin/bash #"Maxl-script" zone starts..... essmsh -l admin password -s localhost -i << EOF spool on to 'dump.txt'; ...
1
vote
4answers
90 views

sed remove end of line for specific lines

I'm trying to find the sed command to remove the end of the line (meaning, get the next line to the current), but only if line starts with the string NOTOK. example input: NOTOK something ...
6
votes
3answers
266 views

emulate tail with sed

I have a mini-system with only limited number of binaries (bash,cp,cat,sed, ...). I don't have tail command, and I am wondering if I could emulate tail functionality with sed cat foo.txt | tail -n 10 ...
-1
votes
1answer
72 views

How to use variables in sed

I want to print out the lines of a file between two indices in a Bash script. I have the file name and indices as variables I tried doing this sed -n "$2,$3p" $1 sed: -e expression #1, char 4: ...
1
vote
2answers
47 views

Using sed to match multiple possible environments in a file

I have some files numbered 01 to 24 that contain things like \begin{thm} blah blah blah \end{thm} \begin{lem} blah blah blah \end{lem} \begin{prop} blah blah blah \end{prop} inside of them ...
1
vote
1answer
59 views

Using sed output in another script or command

How can I use the output of sed in another script? For example (this doesn't work): sed -n "$COUNTER",1p /domains.csv | wget or sed -n "$COUNTER",1p /domains.csv > /myScript.sh As far as I ...
0
votes
3answers
40 views

linux + awk + file manipulation

I have the following file more file.txt 1 2 3 4 4 2 23 4 5 23 2 3 END_OF_LINE 1 3 7 4 2 23 4 6 7 4 2 1 5 How to print only the fields 4 and 5 and 6 until the line END_OF_LINE , and from ...
0
votes
1answer
33 views

rearranging from colum to row in a csv [duplicate]

I have a CSV file that presently has an output like this 1 2 3 4 5 what I need to do is reconfigure the output as follows 1 2 3 4 5 all the entry data on one line, any help would be greatly ...
1
vote
1answer
128 views

Problem with sed on a array containing strings containing spaces

I have a array looking like this: array=("(1 2 3) (123)" "2 31 (231)" "4 5 1 (451)" "(te)xt (1234)") This array is a example. It does not look like this but its structure is the same (the strings ...
1
vote
3answers
63 views

How to add zero (0) in blanks in a big file (example file is below)

Here is a example file where I need to replace blanks with zero A 2 2 2 2 2 B 2 2 2 2 2 C 2 2 2 2 2 D A E B F D R
1
vote
1answer
68 views

Use of sed in perl?

I want to re-use the code given here, but I'm stuck in understanding the use of sed print "Sending to QRadar...\n"; # SSH To QRadar's Console and push out file + trigger update `scp -i ...
9
votes
4answers
99 views

Script to extract selected entries from a bibtex file

I have a large bibtex file with many entries where each entry has the general structure @ARTICLE{AuthorYear, item = {...}, item = {...}, item = {...}, etc } (in some cases ARTICLE might be a ...
3
votes
2answers
227 views

Basic sed command on large one-line file: couldn't re-allocate memory

I have a 250 MB text file, all in one line. In this file I want to replace a characters with b characters: sed -e "s/a/b/g" < one-line-250-mb.txt It fails with: sed: couldn't re-allocate ...
4
votes
3answers
174 views

How to only output lines that are younger than 3 months?

cat a.txt 1387111124 ./asfjlasdf.txt 1348681215 ./akdfyxcv.txt So I need this: cat a.txt | SOMEMAGIC 1387111124 ./asfjlasdf.txt The output should only have the lines that are younger than 3 ...
5
votes
3answers
277 views

Extracting fixed width records with no delimiter from a single line

I need to extract strings of text from a single file containing one very long line of text with no delimiters. Using the sample line below, these are the following known facts: ...
2
votes
1answer
45 views

Matching two different lines that are at least N lines distant from each other

I would like to match files that contain try (in one line) and consecutive catch (in another line) at least N lines later (to find very long try-catches and try to get rid of them). I mean, the first ...
0
votes
2answers
183 views

bash script, printing multiple lines that matching to a specific patern

I have a log file and I'm making a script to do some actions. An action is to print a specific area of the log. Every block at the log starts with a specific time stamp and inside the block may have ...
0
votes
0answers
12 views

Need help in removing specific character [duplicate]

I want to remove the square braces from the file using sed. Please see below. [100] [10] [200] [0] expected: 100 10 200 0 Thanks in advance.
-1
votes
2answers
126 views

How can I force sed to continue parsing when it hits an “invalid” character?

I have a big playlist in .pls format (created with deadbeef playing software) which also contains some badly-encoded strings. Whether this is a bug in deadbeef or one of its plugins does not really ...
2
votes
3answers
70 views

get list of months using dseq from dateutils

how'd I get a listing of the months in the year (abbreviated) using dseq from dateutils? NOTE simply running: dseq 'jan' 'dec' -i '%b' -f '%b' returns a humongous list of months: piping the ...
1
vote
2answers
89 views

Ensure /etc/export contains rule using bash

What's a working example of modifying /etc/export using bash? Example: I want to ensure the following rule is present and valid: /export/home 2400:123::/32(rw,no_root_squash) And it should: Add ...
2
votes
2answers
115 views

stripping out the last two [end] with sed?

I'm working on a script that improves the fluxbox 'menu', and my script has this line: sed -i 's/\[end]//g' ~/.fluxbox/menu;sed -i '/^\s*$/d' ~/.fluxbox/menu but this has the unfortunate effect of ...
4
votes
2answers
61 views

Concatenating fields from lines with different numbers of fields

Given input like this: x y a b c t p q w w t a b c d p q r I'd like to concatenate fields from field 3 up to but not including the last one. If field 3 is the last field, I'd like to insert a ...
1
vote
1answer
92 views

How can sed add text after existing indent?

I have a sed script that has: sed -i '/ *it.*do/! { /\.should/ { s/\.should/)\.to/ s/\(\S\)/expect(\1/ # ...others The last s adds expect( to the ...
1
vote
2answers
138 views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" ...
3
votes
3answers
158 views

sed - how to (not) match unmatched brackets

How can I do my operation only on lines that close their brackets? For example I want to change ".is" lines and add a bracket but not for lines with unclosed brackets. so these are changed ...
4
votes
5answers
286 views

Pattern matching across multiple lines

What is a quick and easy way to validate if the pattern "301 domaname.com 200" is present within BASH when spread across multiple lines of output? I was using something like the following: awk ...
0
votes
1answer
96 views

How can I pass in a parameter to sed?

To be more precise - how can I pass in a parameter to a program that then calls sed - how can I 'pass' that parameter along? I have a file 'source_code.sc'. I have a sed script "find_expect": #n ...
1
vote
2answers
51 views

Replace “-from” with “this” in the begining of line

I want to replace "-from" with "this" in the begining of line. This should happen when that line has 'R' at the end and line above it has "D" at the end. For example for the block shown below: ...
4
votes
4answers
325 views

sed behaves different on FreeBSD and on Linux?

I use both Linux and FreeBSD (specifically, I use Debian Linux and PC-BSD), and I found something weird about sed. I frequently need to convert "tab separated values" files to "comma separated ...
3
votes
2answers
213 views

what is the meaning of this sed command?

sed -e 's/72;/72, next_val = 0x11111111;/;/@/{h;s/test/next/g;x;G}' fmt_vuln.c > fmt_vuln2.c could you tell me about what is the meaning of ;/@/{h;s/test/next/g;x;G}?
5
votes
2answers
83 views

Adding corresponding Numbers in a Range

I have a dataset with 30000 lines. I want to add all the corresponding values (i.e. Column 2) between the range 0-50 and then 50.1-100 and then 100.1-150 etc. (presented in column 1), and this ...
2
votes
3answers
90 views

How to delete a specific line and the following blank line using GNU sed?

I have the following text: Start-Date: 2013-11-11 07:43:49 Commandline: apt-get install --no-install-recommends catfish Start-Date: 2013-11-11 11:27:07 Start-Date: 2013-10-16 22:53:02 ...
0
votes
1answer
69 views

How to add parens around text

How can I use sed to replace text and also append to end of line for the match in question? I have a sed file which is doing many substitutions. One of them changes ~= to match( using /=\~/ ...
0
votes
2answers
699 views

sed - how to exclude multiple patterns in the match

I have currently a set of seds that's working well except for one thing. The particular expression I'm having an issue with is: sed -i '/[^}.to]\.to[[:space:]]/ s/\(\S\)/expect(\1/' ...