"sed" ("stream editor") is a Unix utility that parses and transforms text files.

learn more… | top users | synonyms

0
votes
2answers
176 views

Search, match and replace 1st column with a value using sed

I would like to get some advice using sed on how to replace value1 on first column that matches with value2: value1 = 9999 value2 = 02a-ResetFlag.sh Data File ---------------------------------- 0500 ...
1
vote
2answers
101 views

Replacing every 10th pipe with new line in unix

Lets say I have fields: name, number, id I have a data file: name1|number1|id1|name2|number2|id2...etc I want to replace every 3rd pipe with a new line or '\n' so I get: name1|number1|id1 ...
1
vote
2answers
40 views

How do I print multiple sections in a text file?

I have a text file looking something like this: *FILESTART line_a line_b line_c *INCLUDE file_A.key file_B.key *INCLUDE file_1.key file_2.key file_3.key *SOMETHING_ELSE line_x line_y line_z *END I ...
1
vote
1answer
23 views

Print every line but conditionally only fragments for some lines

I have a text file that looks like this: rno-miR-344-5p miRPlus_11239/mmu-miR-383/rno-miR-383 hsa-miR-301a/mmu-miR-301a/rno-miR-301a ...
0
votes
1answer
35 views

Filtering data with sed

I need a help. I have a file like sometext line 1 sometext line 2 SU0000 ID ID ID sometext line 3 sometext line 4 sometext line 5 sometext line 6 SU0000 ID ID ID sometext line 7 sometext line 8 ...
0
votes
1answer
54 views

Tmux status sed output different from cli

I've been looking at this for a while now, but I cannot find a reason. When I run the following in a cli, it works as expected: $ uptime | sed "s/.*average: \(.*\), \(.*\), \(.*\)$/\1 \2 \3/g" 0.65 ...
0
votes
1answer
74 views

SED: syntax error at script.pl line 19, near “;$'”

I am using this command to delete multiple occurrences of a line in my script and it just works fine when I run it on the command prompt. However when I use this line in my perl script it throws an ...
0
votes
1answer
96 views

Regexp based editing of content in large CSV files [duplicate]

I wanted to remove certain pattern of contents based on a regex from csv file which is very large in size containing 100,000+ records, how is it possible via windows commandline? I also have sed and ...
0
votes
2answers
93 views

Removing Nested LaTeX Tags with Regex

How would I use regex (such as with sed) to remove all \index tags that occur inside any \index tags? For example, a nested mess like this: \index{Test\index{test\index{test}}ing One\index{one} ...
2
votes
1answer
278 views

Use perl to do multi-line replacement [closed]

I have to do some replacements in many *.c files. I want to do the replacement like this: original: printf("This is a string! %d %d\n", 1, 2); result: print_record("This is a string! %d %d", 1, 2); ...
0
votes
1answer
27 views

Replace '-' char using sed

I have a text file, quite similar to this one: JACK BLACK 123456 -1245368 - BRIDGET RED 1245 548425 + JOHNNY HOMUSS 55482 -4325 - I wanted to use a sed command ...
0
votes
1answer
35 views

Sed is not Interpreting Pipes Correctly

OK, this is hard to explain, so I will give a reproducible example: I have a text file test.txt contains the line: somesetting-parameter /an/old/path I want to replace it with a path I can get via ...
-2
votes
2answers
75 views

Trying to count and print song file names using awk

RANK NAME BAND YEAR GENERE DOMESTIC/INTERNATIONAL 206:Reach Out, I'll Be There:The Four Tops:1978:Pop:3/2 207:Bye Bye Love:The Everly Brothers:1950:Classic:3/2 ...
1
vote
1answer
113 views

Zsh autocomplete function with sed

I'm struggling to write an ZSH autocomplete function. My goal is to autocomplete ta's and tk's first argument with the projects listed in tmux list-sessions and tmuxinator list. Here's what I have so ...
1
vote
3answers
106 views

Can anyone explain why this pattern matching is not working using sed

Trying to print out specific times of logs based on recommendation from this thread from super user. I am not sure why my patterns are not being matched by sed. I have the sample date and time I am ...
1
vote
1answer
51 views

Matching only numbers that come in numerical order

I have numbers in [.] indicating the page number of an orginal printed document I am transcribing. However, the document also contains other numbers in [.] that do not correspond to page numbers. For ...
0
votes
1answer
93 views

Bash alias with Sed not working

Does anyone know why this alias isn't working? alias tailsed="tailf error.log | sed -e 's/\\n/\n/g' -e 's/\\t/''/g'" I've tried replacing the single quotes with doubles so that it's like: alias ...
0
votes
3answers
145 views

sed rename files moving numbers to end of file

I have a directory that contains several files with the following pattern. 1953-MADAMA BUTTERFLY 1953-MADAMA BUTTERFLY_001 I'm trying to bath rename them to achieve the following: MADAMA ...
0
votes
2answers
202 views

How can I create a sed command line from diff?

I'm aware that diff -e can output an ed script. And my understanding is that ed and sed share their approach, but that ed is interactive, and sed is for streams. What I would like to do is take the ...
0
votes
2answers
142 views

Installation of Git on Debian 7.4 fails

I tried to install Git (from source) on Debian 7.4, but the installation fails with the following message: Writing perl.mak for Git Writing MYMETA.yml * new perl-specific parameters GEN ...
1
vote
1answer
104 views

sed can't get string match

For the life of me I can't seem to get this to work, no matter how many different combinations I try. I'm trying to recursively search a folder for php files containing a particular string and replace ...
2
votes
1answer
112 views

sed: Removing \r\r before \n in a very large file

I have a corrupted disk image file (about 27 GB) in which before all \n characters \r\r was inserted. I want to remove these \r\r before all \n. I tried with awk: awk '{ sub("\r\r$", ""); print }' ...
2
votes
2answers
238 views

sed: How can I replace \r\r\n?

In this question on stackoverflow it is explained how one can replace a newline character using sed. My problem is that I want to replace the character sequence \r\r\n with sed. Can somebody help me ...
1
vote
2answers
1k views

Bash substring last occurance of a character

I am trying to write a script that removes everything after the last occurrence of a character. For example if the string is DATETIME 2014.03.14 12:23:24, I would like to get just DATETIME 2014.03.. ...
0
votes
1answer
96 views

Extract stings between a delimiter if it matches a certain string

File cat hosts.cfg define host { host_name switchlan alias switchlan address ...
0
votes
1answer
98 views

How to find the matching records from 2 files in unix

I have two files which contains email_ids. 1. Test1.txt 2. Test2.txt Test1.txt contents are: abc@gmail.com xyz@gmail.com mns@gmail.com Test2.txt Contents are: jpg@gmail.com joy@yahoo.com ...
0
votes
1answer
287 views

sed exact match patterns of range and extract lines from thereon

I am trying to extract range from IP= to TUAL_HOSTNAME_=, as below. But its also extracting other match pattern for IP. sed -i -e '/IP=/,/TUAL_HOSTNAME_=/{w /tmp/101' -e 'd}' /tmp/install; #IP= ...
0
votes
1answer
111 views

Sort file with respect to a part of a column

I have one file that contains the details of space in data stores. I want to sort it according to the Free space available in them. File is : Name:VSP-01-32 Capacity:2047 Free Space:144 ...
1
vote
1answer
697 views

How to replace line in file with pattern with sed?

I'm reading a lot of documentation on sed, and am still stumped on my particular use case. I want to replace this line in a conf file with my own line: Replace this line: #maxmemory <bytes> ...
0
votes
1answer
578 views

How to replace text strings by reading in list using sed

I'm trying to come up with a sed script to run from the shell. I need to be able to read in a list of UUIDs from an external file, which contains two columns origtexta replacementa origtextb ...
0
votes
3answers
42 views

Removing a pattern from text file

I have a file riddled with this kind of thing: -POEM- >> The big brown fox >> jumps over the >> lazy dog. The end. I want to get rid of "\n>>" and just turn this into a oneliner: ...
0
votes
1answer
143 views

Linux/Bash: Comment every line matching a pattern

sed is foreign to me, to say the least. I'd like to traverse a C project tree and comment out every line calling the function LogMsg(). Something that'd achieve the following: foreach: line within ...
0
votes
2answers
113 views

Replace string in string but not when its somewhere between double square bracket

I have a long string from mysql field containing the data of a mediawiki page. I have to replace a string in that mediawiki page but not when the string is in mediawiki link. The mediawiki link is ...
2
votes
2answers
151 views

How can sed find pattern in one field but append another(same row)

I have a text file that has comma separated values. Field1 has field that needs to be matched, but field two needs substitution based on the match. Example: A,C B,C Result: A,D B,C I'm guessing ...
0
votes
3answers
776 views

how can sed get patterns from a file

I have two files one holds a list of patterns, another need to be changed based on these patterns. So far I have been experimenting with cat patterns.txt| xargs -n1| sed ...
0
votes
1answer
74 views

How to encrypt the mail in unix?

I want to encrypt the mail as that will be containing the confidential information. There are no attachments. Please help in providing the steps to encrypt the mail. I have got the reference of How ...
0
votes
3answers
87 views

How do I exclude match and change only specific character with sed

I am trying to use sed to replace '0' with the word 'correct' (I am using echo $? to validate my script and I want to replace the output of echo). The problem is that I have more text in the output ...
0
votes
1answer
101 views

How to delete a line from a file that requires permission such as visudo using sed?

I want to add this command timestamp=20 at the end of visudo file which will increase the sudo time for 20 min. This way I'll be able to use my bash script to install many applications. After I am ...
0
votes
1answer
49 views

editing string using sed or grep

first of all please execuse my ignorance on UNIX. I am quite new. I have lot many sql files that contains following string ${DB_USERNAME}.${TABLE_NAME} Can anyone please tell me how could I change ...
0
votes
1answer
179 views

How to insert a comma after every 8th character of a line using sed

How do I insert a comma after every 8th character of a line that has alphanumeric characters including blanks?
3
votes
2answers
533 views

How to comment out multiple line matching a regex using sed or awk

I have a file that contains this: [...] location /static { ... multiple lines ... } [...] location /static/ { ... multiple lines ... } [...] And I want to get: [...] # ...
1
vote
2answers
66 views

Is there a way to print 2 lines (if any) before and after a target or print a placeholder if not?

I'm not native english speaker so I hope to be clear. I know about grep -C 2 "TARGET" inputfile to select 2 rows before and after the row of the TARGET, but I'm not able to use it to manage my ...
1
vote
1answer
27 views

Is it possible to sed -i from a text file to another text file?

I'm coding a shell script on my Debian box and there's a line on the script that needs to delete some emails from a textfile that is full of emails, like this: sed -i ...
1
vote
3answers
115 views

How to select a section from a string in using bash

I have an array containing strings which consist of paths to files in the following format: /path/to/file/14561234545_50303.TXT I'm trying to select the section that is after the "1" but before the ...
4
votes
2answers
2k views

How append a string at the end of all lines?

I'm trying to add a string at the end of all lines in a text file, but i have a mistake... :( Example: I've this in a text file: begin--fr.a2dfp.net begin--m.fr.a2dfp.net begin--mfr.a2dfp.net ...
2
votes
3answers
1k views

Bash script, string not replaced correctly with escaped $ and & characters

I have created a shell script which takes a string as input. If the string contains $ or &, then I need to replace those characters with \$ and \&. I could done that with sed command. After ...
0
votes
3answers
35 views

How to add a character like # to the begining of the 1st nonblank line for several files?

I have a bunch of files, which I would like to use # to comment the 1st non-blank line, the files are not in good format, so there may be 1 or multiple blank lines before the line I want to comment. ...
0
votes
2answers
65 views

Redirect a cat command when using wildcards as input

I have the following command that takes a certain part of a file in the current directory, writes it to a temporary file, gets a part of another file one directory up, writes it to a temporary file ...
-1
votes
2answers
79 views

how to find number of substrings between delimiter? [closed]

I have the string following something(1)^^^something(2)^^^something(3)^^^ ... ^^^something(n) how to find number of something(s) in the string.
0
votes
1answer
88 views

iterating bash script for cycle in a file

I try to make this very simple bash program that must make the following operations: modify a file java n times: every time I must change a single word in a single line of the file (the line is 11) ...