Skip to main content

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.

Filter by
Sorted by
Tagged with
3 votes
1 answer
104 views

Script to format Markdown as plain text

The following script is to convert Markdown files to something closer to my aesthetical expectations. It is not assumed to be bulletproof accurate and I don't mind to slightly adjust the output ...
jsx97's user avatar
  • 133
3 votes
1 answer
160 views

Replace values in key=value configuration files

I have a handful of files containing simple configuration in which I need to modify values. There are some useful constraints that simplify my implementation: The file consists of single lines of ...
Toby Speight's user avatar
  • 79.3k
3 votes
2 answers
138 views

Processing a very long single line of comma-separated (?) floating point numbers

I have a sample svg file from the graphics program Inkscape. My objective is to collect every third pair from a very long line of floating point numbers. That seems simple enough. The larger objective ...
Bryan-StackExchange's user avatar
1 vote
1 answer
68 views

Changing file encoding, removing mid-line LF, and converting DOS CR-LF to Unix LF

We have several thousand large (10M<lines) text files produced by a windows machine. We need to change the file encoding of these files from cp1252 to ...
rxFt20's user avatar
  • 113
3 votes
1 answer
43 views

Split Text to Columns and move all data to the next column

Objective I'd like to confirm if there is a more efficient approach for the working script below, which splits column data in my tsv files. I suspect this can be achieved with awk or maybe sed but my ...
El_Birdo's user avatar
  • 131
3 votes
1 answer
78 views

Bash script to clone directory structure with renaming

I've written a script to aid in creating new watchfaces for the awesome AsteroidOS project. A watchface there typically consists of directory structure like this: ...
Edward's user avatar
  • 66.5k
1 vote
1 answer
89 views

Bash script syncronizing yaml and asciidoc headers using sed

I have a bash script that fixes or creates, and syncs the asciidoc attributes and yaml header for blog posts. It does what it is supposed to. But notice I have put ...
Boyd's user avatar
  • 111
0 votes
1 answer
71 views

Grabbing resolution and offset from xrandr

(using GNU sed) I want to grab some output from xrandr and leave out everything but the resolution and offset. Input: ...
AlpGlide3's user avatar
5 votes
1 answer
48 views

Listing my StackEchange communities user id

Extending this answer solution, I've wrote the following bash script to get the html of my StackExchange accounts page and parse it to a YAML file. The objective ...
artu-hnrq's user avatar
  • 285
2 votes
0 answers
170 views

Bash wrapper for connmanctl with autocompletion

So the idea came from the fact that connmanctl only completes filenames/directories when used non-interactively, whereas when used interactively (executing ...
Enlico's user avatar
  • 527
4 votes
2 answers
212 views

Bash code to install bootstrap in a Ruby on Rails repository

Wrote some code to install bootstrap (latest) in a newly created rails application. update: fixed a typo ...
american-ninja-warrior's user avatar
1 vote
1 answer
456 views

Sed script to update a version number in an RPM SPECS file

I have a specs file: Name: program Version: 2.3.3 Release: 0 ... I want to update the version number every time it's built. I perform the ...
Zhro's user avatar
  • 249
3 votes
1 answer
100 views

Bulk File Rename

A function that funnels all filenames into a file and opens that file in vim. The user then changes the names, saves, and quits. Finally the function renames the files in the folder with the new names ...
user avatar
5 votes
1 answer
506 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: ...
mar627's user avatar
  • 53
9 votes
2 answers
675 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 ...
glenn jackman's user avatar
4 votes
1 answer
94 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-...
simbo1905's user avatar
  • 308
5 votes
1 answer
255 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 ...
russau's user avatar
  • 223
4 votes
2 answers
215 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 ...
Iiridayn's user avatar
  • 143
3 votes
2 answers
141 views

Filter some Apache Conf to extract all ServerName and ServerAlias, then output them one per line

...
Pierre-Antoine Guillaume's user avatar
7 votes
1 answer
2k 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 ...
Rambatino's user avatar
  • 243
3 votes
2 answers
357 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. ...
Kanzey's user avatar
  • 33
4 votes
1 answer
84 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 ...
Weijun Zhou's user avatar
3 votes
1 answer
2k 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 ...
thedev's user avatar
  • 827
3 votes
1 answer
30 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: ...
user3341592's user avatar
3 votes
2 answers
84 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 ...
dont_kill_the_messenger's user avatar
4 votes
1 answer
56 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 ...
Remi.b's user avatar
  • 617
4 votes
1 answer
125 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 ...
prolificslacker's user avatar
9 votes
3 answers
10k views

Transform snake_case to camelCase with sed

I want to convert my_long_variable to myLongVariable in sed. This works: ...
Nicolas Raoul's user avatar
4 votes
2 answers
54 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. ...
Max Starkenburg's user avatar
0 votes
1 answer
48 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 ...
Anthony's user avatar
  • 439
2 votes
1 answer
706 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 ...
Xavier Nodet's user avatar
5 votes
1 answer
142 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 ...
mjswartz's user avatar
  • 171
3 votes
1 answer
45 views

Removing ASCII "frame" around text

I sometimes save nice fortune outputs to my Evernote. The data looks like this: ...
xyz's user avatar
  • 241
4 votes
2 answers
2k 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 ...
sherpaurgen's user avatar
3 votes
1 answer
84 views

Remove line numbers from shell history

I want to parse Linux history output and the commands parts only (without numbers): ...
sherpaurgen's user avatar
3 votes
2 answers
39 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? ...
siema's user avatar
  • 117
2 votes
1 answer
92 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 ...
Hugo G's user avatar
  • 364
3 votes
1 answer
144 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 ...
Marc K's user avatar
  • 133
4 votes
1 answer
268 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 ...
cerule's user avatar
  • 41
4 votes
1 answer
228 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 ...
ivan's user avatar
  • 795
6 votes
1 answer
164 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 ...
Travis Snoozy's user avatar
4 votes
1 answer
76 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 ...
ten1267's user avatar
  • 41
4 votes
1 answer
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 ...
GlenPeterson's user avatar
1 vote
1 answer
230 views

Parsing of a file using sed

I have a file containing lines having this structure : ...
Jeremy D's user avatar
  • 145
1 vote
2 answers
196 views

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

Any improvements are welcome. a.bat ...
user93200's user avatar
  • 139
2 votes
2 answers
785 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 ...
parisminton's user avatar
4 votes
1 answer
610 views

Transpose a matrix using sed

I'm trying to transpose the following data from: ...
user avatar