[SOLVED] Adding carriage return to excel file header
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.
I have an Excel file that has 'CR LF' in every line except the header. The header only has 'LF'. How can I add 'CR' to the header using command line? I assume then the file would have to be rewritten so all lines have 'CR LF'.
For a text file in general, one way to solve the problem might be to run "dos2unix" on it first (which will remove the CRs from all lines where present), then run "unix2dos", which will add CRs to all lines (including the header).
Regarding the Excel file specifically, what format exactly are you talking about? Is the the XML file you extracted from a .xlxs file? Purely out of curiosity, why is the CR/LF details important?
I have an Excel file that has 'CR LF' in every line except the header. The header only has 'LF'. How can I add 'CR' to the header using command line? I assume then the file would have to be rewritten so all lines have 'CR LF'.
As with your other threads, this is no different: SHOW US YOUR CODE.
We can't guess as to what you have to work with. You've not told us ANYTHING about this file (we can only ASSUME it's a CSV/TSV file, since Excel files are a lump of XML/binary junk). We don't know how this is getting generated either, on what version/distro of Linux. Read the "Question Guidelines" link in my posting signature...you need to provide usable details when asking a question; having us ask you each time to provide code/samples/etc., isn't good. Neither is closing one of your threads by simply saying you "added a few lines of code", and not actually SHOWING what you did...the community is here to help each other. You came here for a solution, found one, and then aren't sharing it.
Without knowing ANYTHING about what you have to work with, you could just run
@ TB0ne.........what you have stated makes sense and I apologize for my lack of providing code. Will try to do better from this point forward. I am using an application called EDQ that generates these reports so it doesn't show any code. It's sort of like SQL in a GUI environment. I use EDQ for everything, which shows no code, which is th reason why I only ask for solutions in a command line that I can put in a bash script.
All lines show "CR LF" when viewed in Notepad ++ except the first line (header). The first line only shows "LF", just need it to show "CR LF".
I hope all understands why I cannot provide code and only ask for help that I can incorporate into a bash script.
The file is pipe delimited, no quote characters and the encoding is 'windows-1252'. Another team that I am sending these reports to requires that each line has "CR LF".
@TB0ne.............the other thread you was referring to that I have not marked as solved and did not provide the solution for other to see, I have since added the code that solved my issue and marked it as solved. Sorry all, I am new to this site and will do better.
sed -i 's/\r/\n/' testfile <------ with no extension
But it converts all lines to just have "LF". All lines have "CR LF" except the header line, which shows only "LF". I need only the remaining line(header) to show "CR LF".
sed -i 's/\r/\n/' testfile <------ with no extension
But it converts all lines to just have "LF". All lines have "CR LF" except the header line, which shows only "LF". I need only the remaining line(header) to show "CR LF".
Ok, but it would be helpful to actually see part of what you've got to work with. Again, without an actual 'something' to look at, details are sparse.
Typically, things go from Linux TO Windows, so the \n (LF) is replaced with a CRLF (\r). Try reversing the positions in the command I gave you initially. Also, the behavior you described shouldn't happen...without specifying the entire file with a 'g', sed should only replace the FIRST occurrence. Try:
@szboardstretcher........... I would've thought your suggestion would resolve my issue, but the 1st line(header) still shows only 'LF'.
What is happening after attempting to add "LF CR" to the 1st line of the text file is a timestamp is added to the file along with an extension. Would this affect the text file after adding CR LF ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.