Visit Jeremy's Blog.
Go Back > Blogs
User Name



Great tip to mass edit a file with lots of paths, using variables and "sed"

Posted 12-17-2019 at 08:33 AM by the dsc (linux-related notes)
Tags sed

Sed "default" delimiter is "/", or at least that's what most people use. I tipically find "|" more readable, so that's "my" default. Regardless, it can still be troublesome if you're dealing with paths and variables, it seems somehow the command will "break up".

Glenn Jackman posted on Stack Overflow:
A pure bash answer: use parameter expansion to backslash-escape any slashes in the variable:

Posted in Uncategorized
Views 2879 Comments 0 the dsc is offline
Rating: 2 votes, 5.00 average.

There is more to sed(1) than s///

Posted 10-16-2016 at 05:16 AM by Turbocapitalist
Updated 10-16-2016 at 09:57 AM by Turbocapitalist

There is more to sed(1) than s///

There are books written about sed(1), a stream editor which can filter and transform streams of text, because it can do a lot more than many suspect. It actually uses a very simple and compact language which, though limited, is concise. I used sed(1) for ages and ages without exploring more of what it can do. It's most often used only with the s/// substitution, but it also has other capabilities.
  • selecting or deleting lines
  • alternate
Senior Member
Posted in Uncategorized
Views 2701 Comments 5 Turbocapitalist is offline

sed awk tr etc

Posted 01-15-2013 at 07:33 AM by NullTerminator
Updated 01-18-2013 at 07:54 AM by NullTerminator (add sed cmd for non prinitng char)

A couple sample to strip unreadable characters from a binary file
# Translate junk characters into newlines while squeezing
C:\Temp>tr -sc '[\011\012\015\040-\176]' \n < blob_of_data.txt

# Translate and discard single character lines
C:\Temp>tr -sc '[\011\012\015\040-\176]' \n < blob_of_data.txt | awk "length($0) > 1"
# replace a bad character in a file
0xa0 is a 'non breaking space' that appears often when...
LQ Newbie
Posted in Uncategorized
Views 1209 Comments 0 NullTerminator is offline

Pure-text de-truncator script, a work in progress

Posted 09-30-2012 at 02:28 PM by the dsc (linux-related notes)
Updated 09-30-2012 at 02:32 PM by the dsc
Tags epub, pdf, sed, truncated

Sometimes I want to quote some PDF on pure text, luckily enough it would have actual text rather than being an non-OCRed image, but often there's still the problem that the text on the PDF is truncated/formatted in a fake/dumb way, with actual "new lines" to break the page, which may not make the text completely unreadable when pasted in a text editor, but it's reasonably annoying, and may require quite some time to fix manually.

I'm trying to create a script or one-liner...
Posted in Uncategorized
Views 1480 Comments 0 the dsc is offline

Selecting fields from a line using "sed"

Posted 12-25-2011 at 01:51 AM by Telengard (Here are some things which I hope will be helpful.)
Updated 12-26-2011 at 11:24 PM by Telengard
Tags sed

Yeah, sed ...

No matter how well I think I know sed, it still manages to bite me more often than serve me. Everything I do know about sed, manuals aside, I learned from other programs like ed, vi, and even awk. What I'm getting to is this: my sed-fu is weak, so don't take anything I say about it at face value. Do your own research and learn better for yourself (which you ought to do regardless).

About portability

I'll be using the --posix option with GNU sed...
Views 15064 Comments 0 Telengard is offline


All times are GMT -5. The time now is 12:10 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration