[SOLVED] Stripping out tabs in file before redirecting to command.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Stripping out tabs in file before redirecting to command.
Good morning All,
Real simple question, but for some reason I cannot figure it out. I have 2 files <file1> <file2> that I need to compare and then send to a command. However, the file contains tabs that I must strip out prior to sending to the command.
This is what I got so far:
Code:
lpr < diff file1 file2
I want this to run on the CLI, no perl, no .sh, etc....
Basically I need to now what the argument is that I place next to the '<' to strip out the tabs.
I appreciate your effort but that is not what i am looking for. Yes it removes the tabs out of file1, but it does not compare the files of file1 and file2, nor does it send the output to lpr.
I am aware of sed and all of its abilities, removing the tabs or comparing files or redirecting the output to lpr individually is not the problem. I am looking for an elegant method of doing this in one line.
However, it is not a concise definition of the operator/attribute. It just tells you what <<- does. Unfortunately that does not help, but it does what it says it is supposed to.
That's not any kind of shell syntax I've ever seen, and I doubt very highly it actually works the way you expect it to. Are you using a different shell; c-shell perhaps? We usually assume Linux and bash unless stated otherwise, so you should always mention it when you are using a non-standard environment.
In any case, the link you gave also appears to describe a standard here document, as used by bash and most other shells:
Code:
command <<-ENDSTRING
<tab>a block of text to send
<tab>to the command's stdin
ENDSTRING
This is not what you used above. Heredocs need two identical end strings. And embedded commands don't automatically expand inside the heredoc either. They need to be placed in command substitution brackets.
Also, the extra "-" on the heredoc only strips any leading tabs off of the beginning of each line inside the heredoc, allowing you to indent the contents for better readability. It doesn't strip out any other tabs in the text.
grail's post used bash-specific process substitution, btw, which wouldn't work in any other shell. You would have to use something like temporary files and named pipes to do it otherwise.
Finally, I'd recommend tr instead of sed for removing individual characters from text. It's the most common option for such things.
Last edited by David the H.; 10-13-2012 at 08:36 AM.
Reason: minor rewording
That's not any kind of shell syntax I've ever seen, and I doubt very highly it actually works the way you expect it to. Are you using a different shell; c-shell perhaps? We usually assume Linux and bash unless stated otherwise, so you should always mention it when you are using a non-standard environment.
I will admit that I used this in UNIX, however it was in sh. I assure you that it works and did the job. A lot better and more elegantly than sed and tr. It stripped out the leading tabs as you have mentioned in your post, not trailing, etc. This is the desired outcome. I did notice that I was not specific about that - sorry.
As far as what you have and/or have not seen before, I am not aware of. I am learning the nuances of UNIX/Linux and love to get input from professional individuals. Brow-beating or condescending view points I have no time for. If I have misread the tone of your post please forgive my directness.
I do appreciate the lesson on where I was lacking in my initial post. In the future, I will be more diligent in my verbiage.
But that's just it. The line you gave in post #6 simply can not work in sh, or any variation of it that I know of. And the link you gave doesn't describe the syntax you used or the actions you prescribe to it either.
Either the actual command you used is different from what you posted here, or the command isn't actually doing what you think it's doing. In other words, it's just plain wrong, and only coincidentally giving you what you want in this particular instance.
The best I can guess that's happening is that the shell is erroring out on the improperly designed heredoc, ignoring it and the "diff" word, which it thinks is the delimiting string (in a script it appears to just read to the end of the file), and simply sending the raw text files straight into lpr.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.