Questions tagged [sed]

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

353 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
6
votes
1answer
954 views

Why is sed changing permissions of a file on a cifs mounted share?

I have an Arch linux machine that uses the following fstab entry to mount a share: //192.168.3.1/Documents /mnt/ cifs credentials=/home/tal/.smbcredentials,rw,x-systemd.automount,iocharset=...
4
votes
2answers
140 views

Stuck With Using find and sed to Replace String in Filenames

Following this post as a reference, I'm able to run a find and sed command without it throwing an error, but the filenames remain unchanged. Trying to strip pronunciation_de_ from all mp3s in the ...
4
votes
2answers
2k views

Is the use of sed's “a” command to prefix a line portable?

I noticed the following interesting behavior: $ printf '%s\n' line{1..2} | sed $'1a\\\nPREFIX' line1 PREFIXline2 $ Interestingly, this behavior is only possible for the last command in a Sed script,...
3
votes
2answers
95 views

why is this sed command failing to get the desired output

testfile: 872iirji -- RANDOM STUFF -- skjkfj45j GET /_ajax_htmlview?action=28&__and_so_on HTTP/1.1. Host: my.website.com. connection: blah blah blah skjfkjfj desired output: _ajax_htmlview?...
3
votes
1answer
2k views

Modify filenames in Makefile

For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with ...
2
votes
0answers
52 views

Might this script delete the file if fails?

I suspect that the following script, executed by root, under certain conditions, deletes /etc/hostapd.conf: #!/bin/bash CONFIG_FILE=/etc/hostapd.conf read mac_addr < /sys/class/net/wlan0/...
2
votes
3answers
63 views

using filename and path as strings to be replaced using sed command

I am trying to deal with the following situation. I have many files (more than 100) with an .html extension in a folder tree and inside those files I have a string which is the file name. For example ...
2
votes
2answers
63 views

How to select first occurrence from between two patterns including them

What I have: interface GigabitEthernet0/2/1/6.2061 description --> Some description here service-policy input BESTEFFORT-IN service-policy output Egress_30M vrf VPN-s2s ipv4 mtu 1500 ipv4 ...
2
votes
1answer
49 views

Script to add a block in a few hundred files

I want to add the following lines if ($http_user_agent ~* "somewebsite" ) { return 444; } to all my vhosts in NGINX as follows server { location / { want_to_add_those_3_lines_here } } ...
2
votes
2answers
86 views

merging two files according to the specified row

I have file1.txt looks as follows: search http://google.com mail https://gmail.com file2.txt looks like this: This is a search tool This is your mail account I need to merge them in the way ...
2
votes
2answers
67 views

How can I prepend lines that don't start with certain keywords?

I'm modifying a bunch of python files and I need to prepend every variable declaration with 'self.'. Here's an example of what I'm trying to do. From this: class testClass(parentClass): def ...
2
votes
1answer
244 views

Why is sed failing to follow collate order?

On this command: $ echo "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | > sed 's/[a-z]//g' ABCDEFGHIJKLMNOPQRSTUVWXYZ It seems correct, doesn't it? However, the locale in effect is ...
2
votes
1answer
188 views

Formatting and fill missed data based on column

I have the data in this format and I want to sort it based on the label in each column. Would want to replace the missing field by a comma (,) like shown below 2018-03-13 02:09:12,AB=123,BC=6,CAB=Jax,...
2
votes
1answer
505 views

extract fasta entries from list using while read

I have 28 files that each have ~14,000 "entries". A single entry consists of a header, denoted by >string, a newline, and then a sequence which is a string. Each entry has variable length sequence/...
2
votes
0answers
120 views

sed behaves strange on android tablet

Hi I'm new to using sed When I type: echo day | sed /s/day/night/ the output is: nightday In other words, it just appends the entire line after the substitution. I am using a Samsung Galaxy Tab ...
2
votes
0answers
651 views

Getting a range of lines between timestamps from /var/log/messages

I want to get all lines between two timestamps from /var/log/messages. I only have start time which I provide to my script as input. The script then should get me all the lines till next day as output....
2
votes
0answers
237 views

use gff2fasta instead of a bash script to get parts of DNA sequences out of a full genome

EDIT and a solution Because my original question was badly phrased and I was trying to re-invent the wheel I am answering my own question now (maybe it helps someone else): gff2fasta is a tool which ...
2
votes
2answers
157 views

Replace characters in matched line

I have some text with ip inside it. I'd like to replace each digit in ip which is not followed by "SpecialWord" with some other character. There is can be more than one ip in each line. For example: ...
2
votes
1answer
143 views

Use sed to keep only parts of a file and reorder it (based on textWrangler grep syntax)

I want to edit a file called trial.fastq with the following format: @NAME123.15.1 15 length=151 GTAGCNTACGGGAGGCAGCAGTGGGGAATTTTCC +NAME123.15.1 15 length=151 AAABB#>>AABDGCEGGGFGGGHHHGGGFHHGHH ...
2
votes
2answers
452 views

How to copy strings from middle of lines (between strings) to the end of lines

I have a text file (1.txt) as follows: word1 word2 word3 I use sed to add strings to the beginning and end of every line as follows: sed 's/^/blahblah1 /g' 1.txt > 2.txt sed 's/$/ blahblah2/g' ...
2
votes
2answers
182 views

sed match word1 and word2 to get word in between

Im having issues with trying to pull an ip address our of a log file call full. This is what the line in the file looks like [2016-11-10 11:22:42] NOTICE[24518] chan_sip.c: Registration from '"...
2
votes
2answers
1k views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
2
votes
2answers
201 views

Exchanging One Column From File1 with files from File2

I have two files. The first file has 11 columns, for example: 1 2 3 4 5 6 7 8 9 10 11 The second has 10 columns and might look like this: 11 22 33 44 55 66 77 88 99 100 What I want to do is look ...
2
votes
0answers
294 views

sed stdin behaviour

Using sed for a direct stdin treatment of data, I expect that a line is treated after the enter. This is what happens when I test on CygWin or Linux but on my AIX, a second new line is needed to treat ...
2
votes
2answers
544 views

Compare sets of values from two files and print the output in a third file using awk

I have a problem comparing two files. I'll try my best to explain. I have two files f1 and f2 which I have to compare on basis of two sets Parameter(p) and Value(v). Basically f1 contains a list of ...
2
votes
2answers
948 views

Insert a line after a block of text with sed

I have text file: file.conf ### Option: LogFile # Name of log file. # If not set, syslog is used. # # Mandatory: no # Default: # LogFile= ### Option: LogFileSize # Maximum size of ...
1
vote
0answers
31 views

Capitalise few characters in a word

This might be a crazy scenario but just wanted to know is there any way we can capitalise few of the character in a word without a delimiter (to identify the character to capitalise ) For eg:- I/P ...
1
vote
0answers
60 views

Search and 'in-place' replace strings in binary file

I want search and 'in-place' replace strings in binary file (case-sensitive, colon-separated strings). What method would be more clean, sed or bbe? sed -i.bak 's/F:O:0/B:A:R/g' file.bin bbe -e 's/F:O:...
1
vote
1answer
45 views

sed delete lines not matching patterns in txt file

I'm dealing with a txt file that lists a bunch of other txt files, a lot of which I have wrongfully duplicated. I'm on macOS so the lines listing the duplicated files all end with the pattern (NUMBER)....
1
vote
0answers
32 views

Inconsistent behaviour when piping output of Tail into Xargs through an editing command

I'm giving in to asking the SE spirits for assistance. I will expand in detail below, but I've boiled the inconsistency down to these 3 lines. I am trying to grep a string in between single quotes (...
1
vote
2answers
47 views

Extract method name and add it for logger as first line of method

I have a requirement in which Java method name needs to be added in logger in the first line of the method. I am trying the following approach. Get lines with keyword private, protected or public ...
1
vote
0answers
52 views

how to embed command substitution in sed?

from this answer: Using a command inside a sed substitution there is used this to make command substitution: echo aaabbdd | sed -e 's/a*/echo `echo -n & | wc -m`/;e' When I shell use double ...
1
vote
2answers
50 views

I want to only remove grouped commas from this csv to change the number of variables to two

I have a csv where the first few rows look like this c("4288", "57534"),MIB1 c("2272", "2385"),FHIT c("5550", "10531", "56239"),PREP c("25809", "23669"),TTLL1 I want to manipulate the number of ...
1
vote
2answers
83 views

sed command is not working to remove the special character ( Copyright and trademark symbols )

I am trying to use sed command to delete the copyright characters.But it is not working. Below is the command which am using. sed 's/; © E/; (c)/g' input.txt > output.txt but when am using vi ...
1
vote
1answer
24 views

BASH: Renaming and organizing files based on information in the filenames

Suppose I have a bunch of files has information separated by underscores: nickname_username_realname_date_filename.txt I want to make a directory for each username and rename the file to get rid of ...
1
vote
0answers
47 views

Get entire paragraph by searching single word or multiple

I need your help in scripting portion. I have a configuration file for routers as below, # TiMOS-C-16.0.R5-1 cpm/hops64 Nokia 7750 SR Copyright (c) 2000-2019 Nokia. # All rights reserved. All use ...
1
vote
1answer
41 views

Using sed - how to replace truncated values with separate values within a line?

Example log data: SVCELPTIME=19,FAILPT=9580-8582,MICROSERVICE=YES SVCELPTIME=411,FAILPT=9210-80129210-8686,MICROSERVICE=YES REFNO=JAJRJZ,TXNREFNO=63165718100281723,SVCELPTIME=21,FAILPT=9210-80129210-...
1
vote
0answers
25 views

Sed change only in sector and remove all before pattern

Im stucked. Ive got html files with: Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Random text123 </td></tr></table><a name="Preamble"</a> Random text Lorem ipsum Lorem ...
1
vote
0answers
74 views

“ for vs find ”

I have alot of directories, the name of which are floating point numbers (0, 0.5 ,...,199.5,200). All of these directories contain a text file named p. I want to replace the word value with freeValue ...
1
vote
0answers
41 views

Computing pair-wise time differences in mili seconds between matching records in a data table

I have a three-column table of data of the following form: TIME MPID CPID 14:00:04.909 10048 370007 14:00:05.320 10048 370007 14:00:05.462 10048 370008 14:00:05.761 10048 370008 14:00:...
1
vote
3answers
550 views

Fixed length file replace with sed or awk

I have 487 bytes fixed length file and each record position 407-415 (9 bytes) is a numeric field. Sometimes we are receiving combination alpha and numeric characters in that filed (123ABC123,...
1
vote
3answers
363 views

How to move lines containing specific strings to top of file?

How can I move lines containing specific strings (ie. 005, and 007) to the top of the target file? Contents of target file: XXX_008 XXX_001 XXX_002 XXX_009 XXX_003 XXX_006 XXX_005 ----> located ...
1
vote
0answers
82 views

sed command is replacing the replaced text?

I am writing a bash script to rename icons. Specifically I am trying to change "icon-close-m" to "icon-close icon-size-medium" in HTML files. (though it could contain any substring besides "close", as ...
1
vote
0answers
1k views

replace placeholders in file with the actual environment variables using sed

I have a template file like this: export const environment = { api: { url: '$API_URL', key: '$API_KEY', } } and I was trying to replace the actual placeholder values like this: sed 's/$\...
1
vote
3answers
85 views

Search for a dynamic pattern in a file in a file and replace it with variables

I have written the below commands that will generate three different shuffled vales A=`echo 'abcdefghijklmnopqrstuvwxyz' | sed 's/./&\n/g' | shuf | tr -d "\n"` B=`echo '...
1
vote
0answers
31 views

Merge 2 files based on the 2nd column of each and overwrite common lines in first file

I have a couple of CSVs'. file1 has a large number of URLs and file2 also has a URL field which have to be matched with file1. Now file1 has a couple of columns I need to add to file2. I have managed ...
1
vote
4answers
272 views

remove duplicate and replace it with empty space

I have a table as of below fruits shopname Apple x1 orange x1 banana x2 Apple x3 orange x2 banana x3 I want to group all rows based on column 1 and replace the duplicates with ...
1
vote
0answers
36 views

Sed command writes the expression in outer ifmodule

my config file has this <IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule> I want to change "index.php" to "index.temp" I ...
1
vote
2answers
63 views

Find and replace a word in all files based on file pattern

I have a variable called "User": "x-73098" in multiple files and the file names like astro_root_sys-dev.txt. How to find all the files which have "User": "x-73098" variable and replace that ...
1
vote
2answers
81 views

Not able to replace String while reading the file

The final.txt looks like: build/create_changes.sh build/create_changes.sh-meta.xml src/aura/camping/camping.design src/aura/camping/camping.design-meta.xml And the code looks like this: if [ -e ...

1
2 3 4 5
8