Is "sed" a command line interpreter?

C

CrazedNerd

Guest
the main reason i'm asking this is because i've realized that a major difference between a sed script and an awk is the that an awk script is basically just a bash script, or at least that's how bash sees it.

However, with sed you've got sed -f <script>, and bash can't read the commands you have in the script without the sed command...

Or i guess a better way of phrasing this would be, why don't people tend to talk about sed as a command line interpreter?
 
Last edited by a moderator:


Hmm... They probably don't talk about it like one 'cause it's a stream editor and not an interpreter? I'm a bit familiar with sed, but definitely not a sed guru.

I must be missing something here. Maybe if you elaborate on what you mean by 'command line interpreter' and I might get it better.
 
Hmm... They probably don't talk about it like one 'cause it's a stream editor and not an interpreter? I'm a bit familiar with sed, but definitely not a sed guru.

I must be missing something here. Maybe if you elaborate on what you mean by 'command line interpreter' and I might get it better.
Well, bash just reads your command binaries, keywords, etc. Sed doesn't have keywords and so it's not a "programming language" like awk, but sed had commands, and you feed them to sed through bash or a script like in the example above...

Im mostly just trying to figure out how sed differs from an interpreter...
 
Sed doesn't have keywords and so it's not a "programming language" like awk ...

Hmm... Check the 3.1 of 'help sed'. It does indeed call it 'A 'sed' program ...' (Which I don't recall seeing before, though I've been all through it before. That speaks to my memory and nothing else.)

I'm merely spitballing. Someone else will know more about sed than I do.
 
Awk has a full blown scripting language built into it and is best used when dealing with data that is in rows and columns.

Sed is a stream editor. It also has its own programming language, but it is a little more crude/basic. And primarily deals with transforming text - search/replace operations etc.

It’s possible to write an executable awk script and set awk as its interpreter, using a shebang line at the start of the script.
E.g.
Bash:
#!/usr/bin/env awk -f
And then when you run the script in the terminal/shell, awk will be used to interpret the script.

To run your awk script:
Bash:
/path/to/awkscript /path/to/input-file > /path/to/outputfile

And I think you can do it with sed too.
Bash:
#!/usr/bin/env sed -f
And to run the script, you do the same kind of thing:
Bash:
/path/to/sedscript /path/to/input-file > /path/to/output-file
By default sed outputs everything to stdout. So you’ll need to redirect the output to a new file.

Alternatively, if you want the original file to be edited "in place" by sed, add the -i option to the shebang line in your script BEFORE the -f option:
Bash:
#!/usr/bin/env sed -i -f

Then you’d run the sed script like this:
Bash:
/path/to/sed-script /path/to/input-file
And the sed script will run and will process the input-file, modifying the original file.

Though the ability to use sed like this may depend on which version of sed you’re using. Some versions of sed do not support the use of the -f option. I can’t remember if GNU sed is one of them!

Assuming GNU sed does work with the -f option, then yes, it can be used by bash as an interpreter for sed scripts.
If that’s what you meant by a command line interpreter?!

Just like you can use the shebang to specify Ruby as an interpreter for Ruby scripts. Or Python for Python. Or lci for interpreting lolcode scripts - a scripting language that uses lolcat meme influenced phrases (I CAN HAZ CHEEZBURGER?!). Or chef for interpreting chef scripts, where programs are delicious recipes! (Not to be confused with the chef that’s used by dev-ops in the cloud!)
These are actual scripting languages!!

You can actually build and install interpreters for them and create working programs with them!
Not particularly useful programs, they aren’t really very productive languages to use. But they can be a bit of fun way to flex your brain!

I went off on a bit of a tangent there - sorry about that! Ha ha!
 
Last edited:
It’s possible to write an executable awk script and set awk as its interpreter, using a shebang line at the start of the script.
Good to know,
Just like you can use the shebang to specify Ruby as an interpreter for Ruby scripts. Or Python for Python. Or lci for interpreting lolcode scripts - a scripting language that uses lolcat meme influenced phrases (I CAN HAZ CHEEZBURGER?!). Or chef for interpreting chef scripts, where programs are delicious recipes! (Not to be confused with the chef that’s used by dev-ops in the cloud!)
These are actual scripting languages!!
Even better to know...
 
You can actually build and install interpreters for them and create working programs with them!
Not particularly useful programs, they aren’t really very productive languages to use. But they can be a bit of fun way to flex your brain!
I don't even care that it's useless, i think it's cool that the way to comment out something in lol code is BTW.
 
I was shocked today to discover that the sed manual is only 263 lines, man pages tend to be kinda wierd to just read from beginning to end, but 263 lines is hardly any content at all
 
I was shocked today to discover that the sed manual is only 263 lines, man pages tend to be kinda wierd to just read from beginning to end, but 263 lines is hardly any content at all
Your observation is quite correct.

Gnu utilities, of which sed is one, are usually fully expounded in "info" pages. They write a man page for the utility to comply with UNIX tradition of supplying man pages for most commands, but these are often quite brief, as you found. At the end of such brief pages they usually say so:
Code:
The full documentation for sed is maintained as a Texinfo manual.  If the info and sed programs are properly installed at your site, the command

              info sed

       should give you access to the complete manual.
So the command they suggest is the one to run for the full story.

The info program is a little more involved to run than a man page. It has different commands to run which are more complicated than the manpage format which reads down a page using simple arrow or paging keys. It's possible to sort of achieve something of that manpage formatting with the info page by piping them through less, thus:
Code:
info sed | less
That should run like a single long page that's easy to navigate down as if it's a manpage. The disadvantage of using less is that it doesn't read colour, so the reader doesn't get the normal colour highlighting that man pages have in the modern era.
 
Your observation is quite correct.

Gnu utilities, of which sed is one, are usually fully expounded in "info" pages. They write a man page for the utility to comply with UNIX tradition of supplying man pages for most commands, but these are often quite brief, as you found. At the end of such brief pages they usually say so:
Code:
The full documentation for sed is maintained as a Texinfo manual.  If the info and sed programs are properly installed at your site, the command

              info sed

       should give you access to the complete manual.
So the command they suggest is the one to run for the full story.

The info program is a little more involved to run than a man page. It has different commands to run which are more complicated than the manpage format which reads down a page using simple arrow or paging keys. It's possible to sort of achieve something of that manpage formatting with the info page by piping them through less, thus:
Code:
info sed | less
That should run like a single long page that's easy to navigate down as if it's a manpage. The disadvantage of using less is that it doesn't read colour, so the reader doesn't get the normal colour highlighting that man pages have in the modern era.
I never understood the difference between man and info pages until you explained that, so much appreciated.
 
I don't even care that it's useless, i think it's cool that the way to comment out something in lol code is BTW.
If you like that, check out ArnoldC - a compiled, Java/JVM based programming language which allows you to create programs using nothing but Arnold Schwarzenegger quotes!

This wiki page has a great overview of ArnoldC and contains links to the authors GitHub, where you can download and install everything you need, ha ha!

That said, it looks like there are now some online interpreters for ArnoldC. That’s new! Ha ha!
 
Last edited:
If you like that, check out ArnoldC - a compiled, Java/JVM based programming language which allows you to create programs using nothing but Arnold Schwarzenegger quotes!

This wiki page has a great overview of ArnoldC and contains links to the authors GitHub, where you can download and install everything you need, ha ha!
It'll be either that one or the cooking based one, but i didn't install any of those interpreters b/c there's a really huge amount of information to learn in bash, i googled what the most complicated programming language was and i was shocked that the answer that kept coming back was "JavaScript". I don't understand how JS could possibly be more confusing and hard to learn than C++ or just plain Java, but i haven't studied JS much so i'm probably missing something...
 
It'll be either that one or the cooking based one, but i didn't install any of those interpreters b/c there's a really huge amount of information to learn in bash, i googled what the most complicated programming language was and i was shocked that the answer that kept coming back was "JavaScript". I don't understand how JS could possibly be more confusing and hard to learn than C++ or just plain Java, but i haven't studied JS much so i'm probably missing something...
JavaScript is an ok programming language. It just has some very odd quirks, especially with regards to its typing and scoping of variables. I haven’t programmed in JavaScript for a long time, so I can’t remember any solid examples.

But if you look up JavaScript quirks, you’ll probably see a bunch of examples.

Here’s one article I found:

And that’s just the authors top 5. There are plenty more unusual behaviours in JavaScript!
 
JavaScript is an ok programming language. It just has some very odd quirks, especially with regards to its typing and scoping of variables. I haven’t programmed in JavaScript for a long time, so I can’t remember any solid examples.

But if you look up JavaScript quirks, you’ll probably see a bunch of examples.

Here’s one article I found:

And that’s just the authors top 5. There are plenty more unusual behaviours in JavaScript!
I don't think JS is particularly hard to learn in the sense that pretty much all web development relies on it...so not only does it avoid some operating system and hardware related problems, but a lot of people will be able to tell you the answers to questions.
 

Members online


Latest posts

Top