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

learn more… | top users | synonyms

4
votes
3answers
1k views

How to share a GNU sed script between Linux and Mac OS X

I have a GNU sed script I use on Linux; it is installed at /bin/sed and it seems it contains GNUisms. I have collaborators using Mac OS X. They have installed (non-GNU) sed, located at /usr/bin/sed, ...
3
votes
3answers
176 views

sed + how to remove character/s that start or ended on each number

How do I remove the . character(s) that start in the beginning of each number or end on each number? Remark – perl one liner also good alternative for sed. Example input: .23.12.44.5. .233.3.3.3 ...
3
votes
3answers
184 views

checking data in columns when a data or some may be missing or present?

I am not sure if this possible. say i have columns like : Team Colour Game Rainfall PlayerName XYZ Blue Cricket Yes Kapil suppose i need to search ...
2
votes
2answers
326 views

remove only the first blank line sed

there are similar questions here but none matches my problem exactly. How do I remove only the first blank line from a file using sed? Let's say I have a b c And I want a b c As output.
6
votes
4answers
3k views

Why is sed giving me an error about an unterminated `s'?

I have a set of sed replacements in a bash script and am getting an error about an unterminated `s' command. Here's what the sed line looks like: sed -n -e "s/TMPFOO1/$FOO1/" -e "s/TMPFOO2/$FOO2/" ...
3
votes
3answers
93 views

how to form a sed expression containing escaped characters

Given a sed expression (and GNU sed 4.2.2 on ArchLinux) /match/i\tline1\n\tline2 which should insert two tab-indented lines above the match, I find that the escaping of the first character (in the ...
1
vote
2answers
192 views

Split using sed

I have to split [X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000 at the pipes and output those line whose 2nd and 3rd argument are different.
5
votes
3answers
6k views

Use sed to find whole word and replace

I have the following block of text in a file: test3.legacy test4.legacy test3 test3.kami I only want to search for test3 as a whole and replace it with nothing. Unfortunately, all my attempts have ...
1
vote
1answer
3k views

sed, getting an error: sed -e expression #1, char 28: unterminated `s' command

When I do: sed 's/@driver.quit/#@driver.quit' set_QA_district_name_spec.rb I get the error shown in the title. How can I get around this error, what is wrong?
4
votes
2answers
1k views

sed pattern space and hold space

i was just going thorugh this and i was unable to understand. sed -n '1h; 1!H; ${ g; s/foo\nbar/bla\nblub/ p }' file. where cat file is : foo foo bar why there is 1!H because to me 1h ...
1
vote
2answers
321 views

Delete lines until a header with sed [closed]

I am incorporating SED into a Windows batch file. I've got it working for deleting the first seven lines of a text file: SED "1,7d" However, I'd like to make it a smarter statement. Essentially, ...
4
votes
3answers
6k views

How can I use SED or AWK to replace placeholders in a template file with variable content that contains special characters?

CentOS 6.3 I'm trying to get a small script to send an email containing a copy of email headers in the body (for the purpose of internal reporting). The template file contains the following: ...
4
votes
3answers
2k views

Remove string from a particular field using awk/sed

I have a file (>80,000 lines) that looks likes this: chr1 GTF2GFF chromosome 1 249213345 . . . ID=chr1;Name=chr1 chr1 GTF2GFF gene 11874 14408 . + . ...
1
vote
3answers
96 views

Does sed write to the file or give a sample output

when using sed with a file like this sed 's/a/o' fruits it gives the necessary output to the terminal but it does not change the contents in the file. How do I permanently change the file with the ...
0
votes
1answer
985 views

comparing lines with awk vs while read line

I have two files one with 17k lines and another one with 4k lines. I wanted to compare position 115 to position 125 with each line in the second file and if there is a match, write the entire line ...
1
vote
1answer
717 views

Coloring the output of conky-cli in dwm

I've recently installed conky-cli and got it running on the upper bar in dwm with this simple command: conky | while read -r; do xsetroot -name "$REPLY"; done & And I wanted to get colored ...
6
votes
4answers
3k views

How to remove multiple blank lines from a file?

I have some text-files I use to take notes in - just plain text, usually just using cat >> file. Occasionally I use a blank line or two (just return - the new-line character) to specify a new ...
1
vote
2answers
281 views

How to count the number of words and print the lines that match exactly a given pattern?

I want to count the number of words and print the matched pattern lines which matches exactly with following pattern: abc-ERROR: The input File contains: # abc-ERROR: xyxxkkfgfr # def-Error: ...
1
vote
2answers
57 views

Trimming one part if equal to another part?

I use an e-mail quote attribution string like this: On dd mmm yyyy hh:mm +hhmm, from info@example.org (Example Dot Org): where info@example.org is the sender's e-mail address and Example Dot Org is ...
8
votes
2answers
968 views

Deleting all C comments with sed

I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed, and this is what I have so far: sed -i '/ * [^()] ...
0
votes
1answer
100 views

Comment the if statement and the matching endif keyword

In vim, I can find the matching if statement and prepend the appropriate comment symbol. (e.g. %s/.alarm./#\0/g), but then I am left with dangling endifs that I have to find manually. I could simplify ...
0
votes
2answers
262 views

Reordering strings in linux

How can I change lines around using the command line? e.g. I have these lines: Acct-Status-Type = Start User-Name = "37XXXXXXX" Event-Timestamp = "Apr 12 2013 15:56:55 AMT" I need to ...
0
votes
1answer
98 views

Optimizing sed command or create new one

I'm a newbie in Linux scripting, especially for using sed and awk commands. For now I'm trying to filter a really big log file and wondering if there are any alternatives for my commands? or some ...
3
votes
3answers
2k views

Delete XML node containing certain element

I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed: <Placemark> ...
0
votes
1answer
189 views

replacing text and deleting text using awk in file using

I have a script and I want to do some replace and delete operations on it. I used sed to extract values between words SendCommands and end like this sed -n '/SendCommands/,/end/p' ddtt As awk was ...
0
votes
2answers
55 views

How to delete lines where the given part of the line is more than 100 chars?

I know I can delete lines that are longer than 100 chars with this: sed '/^.\{100\}..*/d' But I have the following example line: <a ...
2
votes
2answers
320 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
3
votes
1answer
7k views

Replacing string based on line number

I have a situation where i want to replace a particular string in many files Replace a string AAA with another string BBB but there are lot of strings starting with AAA or ending in AAA ,and i want ...
2
votes
1answer
665 views

exchange two words using sed

I am trying to exchange two words in a line but it doesn't work. For example: "Today is my first day of university" should be "my is Today first day of university" This is what I tried: sed ...
0
votes
3answers
107 views

Grep end regex matching

On OS X, system_profiler SPHardwareDataType outputs: Hardware Overview: Model Name: MacBook Pro Total Number of Cores: 4 L2 Cache (per Core): 256 KB L3 Cache: 8 MB Memory: 8 GB I want to ...
2
votes
1answer
84 views

Deciphering sed commands

I just run across the following sed command: sed "s|^/samba|\\|;s|/|\\|g" I have seen sed substitute commands before. I also know sed allows the usage of any character as a delimeter (| in this ...
3
votes
4answers
564 views

Colored output in less when tailing a logfile

I am in dire need of a way to color my less output while reading a file that is constantly being appended. The file in questions is a Resin servlet container log. My current "implementation" of the ...
1
vote
1answer
117 views

What does x option for sed do actually when exchanging data between hold and pattern buffer?

I dont understand what x does when it comes to exchanging the contents of hold and pattern buffer.Does it exchanges the data between hold and pattern so that any previous data in hold or pattern is ...
1
vote
2answers
236 views

Regex and piped commands with sed

I'm finding really hard to use sed command, plus I can't seem to find well written tutorials. Let me say that I worked with regular expression in other languages (Python, JavaScript, Java), so that ...
2
votes
2answers
1k views

Using sed to process passwd file

I am trying to learn sed, but I'm having a lot of trouble. What I am trying to do is process my passwd file using a bash script with sed commands to do the following: For every user with group ID ...
1
vote
6answers
6k views

How can I use variables when doing a sed?

I want to do: cat update_via_sed.sh | sed 's/old_name/new_name/' > new_update_via_sed.sh in my program. But I want to use variables, e.g. old_run='old_name_952' new_run='old_name_953' I have ...
2
votes
3answers
320 views

awk, sed, grep, perl… which to print out in this case?

I have this syntax in a file (http response times from analog): <thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
-1
votes
1answer
186 views

Replacing part of a string with another part of that same string [closed]

How would I go about replacing part of a string with another part of that same string, in a bash script, using sed?
3
votes
1answer
62 views

How to edit files in-place while performing operation on the values matching the searched pattern?

Given a list files containing random text and many datetimes in ISO format in it (e.g "2012-07-02T10:47:24+02:00"), how can I find all these datetimes and add 2 hours to each one ? Ideally a solution ...
2
votes
3answers
1k views

Bash commands/script to remove a line from CSV with duplicate in column

I have a lot CSV files that I have combined. However, there are duplicates, but the entire line is not duplicated. I do have a column that I want to use as the criteria to search for a duplicate. ...
1
vote
3answers
581 views

Newbie struggles with grep, sed, awk to filter html

I am a beginner linux user, trying to teach myself how to use linux tools on a cygwin install. I decided to make up a project to try to teach myself the basics of shell scripting and simultaneously ...
3
votes
4answers
1k views

Replacing pattern after nth match is found on each line?

I have a file containing lines: india;austria;japan;chile china;US;nigeria;mexico;russia I want to replace all the occurences of semicolon on each line with e.g. ;NEW;, but starting from the 2nd ...
0
votes
1answer
47 views

How can I update this sed oneliner?

INPUT: $ echo -e 'AAAART5530408XXXX\nAAAAZE6530408XXXX\nAAAART12345678XXXX' AAAART5530408XXXX AAAAZE6530408XXXX AAAART12345678XXXX $ OUTPUT: $ echo -e ...
1
vote
1answer
113 views

How to parse this output and put it into an array?

i have expect script whose output looks like : I would like to extract all words like Gi/02/12 etc in an array or a list. VLAN Name Status Ports ---- ...
0
votes
2answers
790 views

How do i remove all occurences of semicolon from the end of all lines?

These are the steps i am following. `sed 's/[;]+$//g'` also sed 's/;{1,\}$//g'
1
vote
2answers
75 views

Match ids and print original file

I have two files Original: (5000 entries) Chr Position chr1 879108 chr1 881918 chr1 896874 … and a file with allele frequencies (2000 entries) Chr Position MAF chr1 881918 0.007 ...
-2
votes
1answer
294 views

Search low values in mainframe files

I am working with mainframe files and it seems that the low values (x'00') exists in the records in the file which throws off my import for fixed block. Does anyone know how to eliminate those ...
2
votes
2answers
8k views

How can I replace text after a specific word using sed?

I have a file named .ignore. In need to replace the projdir. For example: ignore \..* ignore README projdir Snake I need to replace Snake with, for example, "PacMan". I read the man page, but I ...
0
votes
2answers
193 views

sed extract with multiple options in end pattern

I get some output from a command, I have to extract text between two patterns from the output. Start pattern is fixed. But the end format can be one of two (lets say word2-1 and word2-2). Is there ...
3
votes
7answers
1k views

Is there a faster way to remove a line (given a line number) from a file?

A related question is here. I often have to edit a large file by removing a few lines from the middle of it. I know which lines I wish to remove and I typically do the following: sed ...