Questions tagged [sed]

Sed stands for Stream EDitor. It is one of the basic tools in the POSIX environment - it processes one or more files according to an editing script and writes the results to standard output. Created in Bell Labs, it has been around since mid-70s.

8
votes
2answers
539 views

Bash script to truncate subject line of incoming email

I'm going to put this script into production in a mail server /etc/aliases file: we have a system that receives email but the subject line must be limited to a certain size. The proposed usage in the ...
6
votes
1answer
295 views

Updating my package version using only a Makefile

So I have written a Makefile that has a release function that can be run like: make release bump=patch and I want it to be fully ...
6
votes
1answer
114 views

Bash script to convert NIST vectors to debug scripts

TL;DR: The Bash script converts a published, somewhat-structured text file into a format usable by my testing infrastructure. It's slow, I think it's ugly -- although it is fully functional. The NIST ...
5
votes
1answer
67 views

sed to fix a messy nginx.conf

I have a few servers to fix that repeatedly get their nginx.conf file messed up due to a rogue deploy script. These are the three sed commands I'm using to fix at present: ...
5
votes
1answer
59 views

Sed script that removes specific lines in `seq` output

I have a file to process with sed but I am not quite familiar with the commands with capital letters used for multi-line patterns. I use ...
4
votes
1answer
66 views

Select second field in text table with shell script

I am writing a bash script to mount openshift service accounts into kubernetes objects. The right secret to use is highlighted in this text: $ oc describe sa sa-...
4
votes
2answers
50 views

CGI for htpasswd registration

I decided to go with a very simple CGI user registration program to pair with Apache's mod_auth_form wrapper around a private site. It was only just after I ...
4
votes
2answers
31 views

Isolate URLs from other text around it and put each on own line (with sed)

I have a small shell script that uses sed to take an input file of URLs with hand-written notes around them and strips the notes and puts each URL on its own line. ...
4
votes
2answers
1k views

Using sed regular expression to extract domain name from file

I'm learning regex with sed to extract the last field from file named "test". The method I'm trying gives desired output. Please suggest if this method Im trying is ...
4
votes
1answer
40 views

Iterate over files and convert with a new name / directory

I'm pretty new to bash scripting. I want a script that I can run in a directory that contains .md files, runs pandoc on them, and delivers the output to a sibling ...
4
votes
2answers
2k views

Transform snake_case to camelCase with sed

I want to convert my_long_variable to myLongVariable in sed. This works: ...
4
votes
1answer
2k views

Bash Shell Script uses Sed to create and insert multiple lines after a particular line in an existing file

This code seems to work, but I'd like someone with shell-fu to review it. Is the temp file a good idea? How would I do without? Is sed the right tool? Any other general advice for improving my shell ...
4
votes
1answer
220 views

Using sed to implement the cp command

I have a script for school that mimics the cp command. Part of the assignment is to modify the script so that the while loop (that assigns ...
4
votes
1answer
179 views

Find-grep-sed for project-wide search & replace

I always forget how to do this efficiently with Vim's arglist. Drawing inspiration from a post over at Stack Overflow, I wrote a Bash function to perform a project-wide search & replace. It does ...
4
votes
1answer
532 views

Transpose a matrix using sed

I'm trying to transpose the following data from: ...
4
votes
1answer
66 views

Try every option for a command and make anagrams out of the successful ones

What I have: I am trying to find what words you can make out of Linux command options like ls -cat or ps -elf. To do that I am ...
4
votes
0answers
62 views

SLOC Counter Script Optimization

I'm a HPC guy so I'm all about "make it work, then make it fast." I have a little bash script which gets a Physical Source Lines Of Code (PSLOC) and Logical SLOC (currently just of Java code, but it ...
3
votes
2answers
71 views

Enable or disable sections of a model according to user input

I am using sed command to comment in or out sections in my model according to user input (commenting is done by prefixing the line with !). Once this is done, I ...
3
votes
1answer
39 views

Remove every line that include and follows the second occurrence of a given pattern

From a file, I am trying to remove every line that include and follows the second occurrence of a given pattern in Bash (Mac OSX). Note, that a file may have only one match of the given pattern (and ...
3
votes
1answer
40 views

Removing ASCII “frame” around text

I sometimes save nice fortune outputs to my Evernote. The data looks like this: ...
3
votes
1answer
64 views

Remove line numbers from shell history

I want to parse Linux history output and the commands parts only (without numbers): ...
3
votes
2answers
35 views

Changing filename and copying in bash

I wrote a script which changes names of last downloaded songs and copy them to music directory. Can it be written better? ...
3
votes
1answer
72 views

Extracting performance statistics from FTP session transcript

I've borrowed and written the following code to output the disconnect time. All works well but I'm curious as to how I could tighten/ shorten the code. If anyone feels like having some fun then I'd ...
3
votes
2answers
50 views

Bash script for managing hashtag notes

I have written a simple script for managing hashtag notes. I am not familiar with bash scripting so I would really appreciate it if someone could give me some pointers about it. ...
3
votes
1answer
21 views

Accelerate set of sed commands in files (recursively over full directory)

I run this to fix some hard-coded references, replacing occurrences of mywar by clientwar: ...
3
votes
1answer
101 views

Changing cuts to sed for parsing dates from apache log (common log file)

Would switching my cuts below to SED improve performance? I am trying to get a per date count of requests for the last two weeks from a server log. The script runs, but slowly (comes in around 14 ...
2
votes
2answers
747 views

Adding a zero to file names

I've recently discovered the power of sed; regular expressions seem like they'll take a lifetime to master. This tiny script uses both to add a zero before the single digit in file names. Can this be ...
2
votes
1answer
650 views

bash script - sed - template file processing

Using a bash script to process a file and pass it to AWS CLI. The script runs inside a docker container. I'm using sed to do template string replace. When MY_VALUE ...
2
votes
1answer
449 views

Finding hidden field values in a web page before submitting a login form

In order to submit a login form using wget, I need to find the values for the hidden field that were added to the form recently. Grepping for the names gives the ...
2
votes
1answer
64 views

Parsing logs in sed efficiently

I have an application which log file has most lines start with a time/date, followed by a debugging level and the actual log message. Often I want to watch the output live and colors make it a lot ...
1
vote
1answer
193 views

Parsing of a file using sed

I have a file containing lines having this structure : ...
1
vote
2answers
186 views

Add getters and setters to a set of variables [closed]

Any improvements are welcome. a.bat ...
0
votes
1answer
36 views

Loading a file in vim via piped output of ag

I feel as if my scenario is fairly simple but that I might be overcomplicating it. I am searching through files looking for a special condition, that is where the method ...