Tagged Questions

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

learn more… | top users | synonyms

1
vote
1answer
8 views

Using grep, sed or awk to find words in between? I want to be able to extract the package name until .el7

I am writing a script (bash/command-line) and I want to be able to extract the package name until .el7 x=dbus-sharp (an example package name - which changes) example text file: Building ...
0
votes
0answers
26 views

GnuWin32 / sed unexpected behavior in Powershell

I am using GnuWin32 tools on Windows Command Line/Powershell. What is see: 11:15 enlil D:\Users\x> Get-ChildItem .gitconfig | sed "s/ */ /g" D i r e c t o r y : D : \ U s e r s \ x M o d ...
0
votes
2answers
15 views

how to retrive value between double quotes with multiple double quotes in line using sed

I am trying to use sed to retrieve value of 'identifier' from below line which is string 'TestStudioJobResponseMessages' in below example, also I don't want to use string uuid in my sed expression as ...
0
votes
1answer
29 views

Awk script to run a command based on condition using 'if'

I have a piece of code here that basically takes a file called 'srcip' (which is just a list of IP addresses) and compares it to my '~/db' file which is just a tab delimited IP HOSTNAME database of ...
0
votes
1answer
34 views

is there a way i can either insert a character into a line or substitute and arbitrary character with itself plus some other carachter(s) in sed?

like say i have a string of numbers that constitute a phone number and are like so ########## and i want to format them like : ###-###-#### insert only puts in new lines, and i dont know how to ...
0
votes
1answer
20 views

How do I search for and delete just the endings of list of directories using 'sed' command?

How do I use sed to delete just the '-bak' portion of the following list of directory names: accesscode-bak adminconsole-bak adoptimizer-bak ads-bak ahcms2-bak alerts-bak alfresco-bak
1
vote
2answers
40 views

Grep output from multiple lines in a limited shell environment

I have been scouring the web for ways to search across multiple lines of output and then print the lines which contain the strings I care about. I am actually running this on a checkpoint firewall, ...
-3
votes
2answers
37 views

How can I use a “<” character in sed?

I am trying to replace this line with a <?php tag with sed using the command: find . -name "*.php" -type f -exec sed -i '/if(!isset($GLOBALS/<?php/d' {} \; When I run the script, it generates ...
1
vote
2answers
34 views

how to see contents of a file (cat file) but eliminate a certain string in many lines

I have a file like this: ins.pro.server.pro.net ins.pro-server2.pro.net ins.pro-server3.pro.net ins.pro-server4.pro.net I would like to cat this file but eliminating the specific string ".pro.net" ...
1
vote
1answer
51 views

Bash/Sed how to insert a string with special characters into a file

I have a script that I'm currently working on. And I've run into an issue where I need to prompt a user to enter a string, then encrypt that with sha-512, and then insert it into a specific file So ...
2
votes
2answers
28 views

Replace Line Breaks on matching lines, using AWK

I have the following data What i'd like to do is for every line, where there is no ,"555" at the end, I want to remove the the line break, \n, and replace it with space. So, the 'matching line' ...
0
votes
0answers
38 views

how to show battery percentage on gnu screen hardstatus line

I currently have this as my hardstatus last line on gnu-screen the ~/.screenrc entry is as follows (just incase someone want something similar) hardstatus alwayslastline '%{= g}[ %{G}%H %{g}][%= ...
1
vote
1answer
23 views

Get a range of lines from a file and replace a line in that range using awk or sed or both

I would like to replace a line in a section of the smb.conf file using either awk or sed or both if need be. Here's the section in the file... [CMI] oplocks = no wide links = no writeable ...
0
votes
1answer
21 views

Why this sed is not working?

I want to massively change some css references in more than 200 html files. Most of the files are static HTML generated automatically. Now, I need to change the location of some css files. So, I ...
0
votes
1answer
26 views

Extract text between two slashes and add it at the end of the line after a tab character

I have a text file looking like this: data/CON/001/raw_series_ST_MC_REG_SM.nii data/PAT/001/raw_series_ST_MC_REG_SM.nii I would like to achieve something like this: ...
0
votes
0answers
10 views

Sed :cant read scripts/MIRRC.in: No such file or directory

I'm trying to install miriad and while entering sed -e "s,@MIRROT@,$MIR,"scripts/MIRRC.in &gt; MIRRC " I get the error below sed: Can't read scripts/MIRRC.in : No such file or directory I'm ...
0
votes
2answers
80 views

Bash script: Use variable in sed to delete all but the last “x” lines of a file

i'm using the following bash script to delete all but the last 'x' lines in a log file: #!/bin/bash # Script to write to the log file every minute and delete all but the last # set time in hours ...
0
votes
1answer
23 views

Return / transform then return pattern with nulls

I'm using grep/sed to parse a large binary file full of nulls for some specific data. This is in a windows environment using gnuwin32. Assuming I had some to return some data from a binary file that ...
0
votes
2answers
11 views

How To Search & Replace From a Word to another in The Same Line?

Like I said,, I want to search each line, from a word at the beginning of the line, To another word at the end ! For Example, let's say that I've a text file, that contains these lines :- 1.RA.xm: ...
0
votes
1answer
22 views

Remove beginnings of email addresses from text using grep or sed

I have a text file with lines like the following: John Stevenson Johnnyboy34 john.stevenson@company.com 0320423\n Mike Anderson AndersMike mike@mikeltd.foo 0234234 How do I remove the "text" ...
2
votes
2answers
41 views

How to find the common paths from a list of paths/files

Prelude: Given a sorted input of a list of paths/files, how to find their common paths? Translating into tech term, if feeding the sorted input from stdin, how to pick the shortest proper prefix ...
0
votes
1answer
27 views

Bootstrap pkgsrc on macosx (10.9) error

I am trying to bootstrap pkgsrc-2014Q2 on OS X 10.9. The script complains: cd /Users/tiramo/Downloads/pkgsrc-2014Q2/bootstrap/work/wrk/pkgtools/bootstrap-mk-files/work/bootstrap-mk-files-20140516; ...
0
votes
1answer
31 views

Is \d equal to [0-9] in sed?

7 00:00:30,008 --> 00:00:30,066 by line 8 00:00:31,038 --> 00:00:34,050 or later in the nineteen seventies it was usually a 9 00:00:34,005 --> 00:00:38,634^M video consul but the council was ...
0
votes
1answer
41 views

How to pass output of command to sed

My sed command in #Update key in config file. does not get the contents of the variable $GETKEY Someone help me? # Get key from output of the website. GETKEY=`wget https://www.badips.com/get/key ...
0
votes
0answers
20 views

binary substitution in (audio)streams with bbe or sed

I try to do some stream manipulation with webradio streams. Goal is to use a pattern in triggerfile to substitute some seconds of the instream to silence in the outstream I found bbe to possibly fit ...
0
votes
2answers
166 views

Increment version text stored in a bash script file

I have a bash file and I want to store a version text in it (preferably "echo version 1.0.1" so that it automatically prints out its own version when executed) I am trying to make a command group ...
0
votes
1answer
70 views

sed: What does exit code 2 mean?

Case I am trying to replace all occurrences of <value>*</value> into <value>file:\\</value> in a designated file test.txt. I work on Windows and use sed I have installed with ...
1
vote
1answer
44 views

Run sed as a one-off ssh command

I would like to substitute a string with another in a file on a server of mine. I've tried doing this: ssh $REMOTE_HOST sed 's|export ${KEY}=${VAL}|export ${KEY}=${NEW_VAL}|' "$ENV_FILE" And a ...
0
votes
1answer
42 views

Replace negative values in a file with zeros

I want to replace all negative values in a file with zeros. How can I do this in awk? I tried with gsub but gsub(-*, 0) doesn't work... Any ideas? My "code" is awk '{gsub($(!/-/),"0",$2); print $1 ...
3
votes
3answers
68 views

Sed replace only in even numbered lines of a file when replace commands are written in a file

I have all the replace commands in a file (say replace.sed) and i use it with -f flag of sed (sed -f replace.sed InputFile). But now i ran into a condition where i need to apply these replace rules ...
1
vote
1answer
49 views

Non case sensitive search case sensitive replace

How do I search/and replace like this using sed or another tool FOO => BAR Foo => Bar foo => bar That is: Look for foo regardless of case, and replace with the same case pattern. One ...
2
votes
1answer
230 views

sed, insert file before last line

The following inserting file method for sed used to be working, even before last line, but not any more. Is it a bug in the current sed? Demo of inserting file method with sed: mkdir /tmp/test ...
0
votes
0answers
16 views

How to colorize the output using sed - no GNU tools available

I'm using a short alias in my .profile file to colorize the output of the sdiff command, just to make it easier to spot differences. The alias is like this: alias color_diff="sed 's/[|< |> ...
0
votes
1answer
29 views

Escape brackets when using SED

I would like to replace the value varchar(36) with char(36) in a file by using sed. I am trying with sed -i ’s/varchar(36)/char(6)/g’ calls_contacts.sql But the command does not execute. What am I ...
0
votes
1answer
89 views

How to replace a line in an xml file with a set of lines stored in a variable or file using unix commands?

I have a xml file in which the line that needs to be searched is: SEARCH='<?xml version="1.0" encoding="UTF-8" standalone="no"?><SSC>' This searched value needs to be replaced with ...
2
votes
2answers
193 views

sed error when launching terminal on OS X

I get these error messages when launching bash or zsh in standard Terminal.app or iTerm2 sed: 1: "\#^system_type=# { s#^s ...": extra characters at the end of p command sed: 1: "\#^system_type=# { ...
1
vote
2answers
85 views

Adding text to the end of multiple files, minus one line( Adding return 0; at the end of each program in C)

I have a bunch of C programs from K&R and of course, no return statement. I was wondering if there was a way to cat to the end of each file (except one line before the end, so EOF - 1) the ...
0
votes
0answers
31 views

How to call “sed” on PDF files

I am able to find text on PDF files using pdfgrep. How can I sed them? I just want to change a pattern of text and I don't think I need a editor for that. Or do I? How can I achieve that?
0
votes
1answer
29 views

How to use sed to examine the line without specific content?

I made a toy file named toy, its content is like: aaa bbb My first idea is to use: sed -n '/[^a]/ p' toy bbb it prints out bbb, but when I added bb ab to the end of toy file. I found it lose ...
-1
votes
2answers
76 views

add line number after matched pattern in vim

I have raw sequences and I have to convert it to fasta format. so reads are like this: CTACGGTGTGCTCTTCCGATCTGACTATG AGTTGGTGTGCTCTCCCGATCTCGCTCCCTC GTGAGGTGTGCTCTTCCGATCTCCGGCAGTGTGCT and i want ...
4
votes
2answers
256 views

shell script to replace a keyword in a file with the contents of another file

I'm to create a .sh to replace a specific keyword in a file using the contents of an other file. template.html contains a unique string "PLACEHOLDER" it must be replaced with the contents of file ...
2
votes
4answers
79 views

Extract lines based on long list of line numbers

I have a long list of line numbers (35389208) that I do not want in my file. By line number I mean the line in my file (e.g. line 277). My list of line numbers I do not want looks like: 277 278 279 ...
1
vote
1answer
307 views

Apache as Proxy replace the html code/tags/text

I configured my apache2 server as a proxy server. I added some filters to my proxy.conf file to change the text (html source code) of the websites. Example code: ExtFilterDefine foodo mode=output ...
3
votes
1answer
171 views

Using sed with parallel gives empty output when redirecting to file

I'm using the zsh shell. I am trying to use sed to substitute some text in many files, using parallel to speed up the process. When I tested this on one file and let the command output go to stdout I ...
0
votes
1answer
120 views

using sed to replace 1 line with a multi-line variable in ksh

I have the following text in a file: XXXX NNNN YYYY NNNN ZZZZ NNNN I want to replace the NNNN to make it look like this: XXXX NNNN DUTY FORECASTER: YYYY NNNN DUTY FORECASTER: ZZZZ NNNN ...
1
vote
2answers
967 views

Properly escaping forward slash in bash script for usage with sed

I'm trying to determine the size of the files that would be newly copied when syncing two folders by running rsync in dry mode and then summing up the sizes of the files listed in the output of rsync. ...
0
votes
1answer
100 views

GnuWin32 sed how can I search and replace quotes? Win7 UK

Getting really weird behaviour with sed in Win7: Manual says surround substitute command with single quote (') - rejects, only allows double quote ("). Plus I want to change double quote in a file to ...
0
votes
2answers
172 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
89 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
39 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 ...