ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Need help on reading a file that is in two columns and recreate an output file with all the data in one column. Need to know how to open the file, read 66 characters for 53 lines, store it and print it out and then take the 67-132 characters and print them under the first column.
I'm new to shell scripting so ANY help would be greatly appreciated. I will answer questions as best I can.
hi, what have you attempted so far and what roadblocks are you facing. have you asked your teacher for examples that mite give you ideas to tackle the problem ?
I have just started. Teacher? This isn't a school project. The guy who usually does this is out this week and I've been tasked to do this. I've only modified existing scripts (none open, read and/or manipulate a file) and I need to create one and not sure how to do it.
Any help to a newbie would be greatly appreciated.
I have attached a sample output file. Notice the two columns per page and need to make first column print out and column 2 on page one print out under column 1.
What is awk? I see what you're doing here but not 100%. Not sure what awk is.
Output currently is first column is from top left corner, 66 characters per line and 54 lines down. Second column starts at character 67 through the end of the line and the 54 lines down. That first column should be printed on one sheet and the second column printed under the first column to make the output file one column long.
This problem is more complex than what one would usually do with shell scripts. The big complication is that not only is the data in columns, but there are page breaks within each column. You have two columns per page, so for a two-page file, you have four parts. Presumably, when you put the whole thing into one long column, you want to adjust the page breaks accordingly. Or perhaps you want the page breaks removed altogether. In reaching a solution, it would be useful to know if all reports are two pages or less. The problem is not fully specified.
nittmann: that is quite strong language for someone with 7 posts in LQ, and no rep. I would guess that mods would ask you to lighten up a little. When you say 'I will not comment on other posts', and then quote from those posts, that is commenting.
Pseudo code.
(1) Initialize two arrays each containing 53 rows.
(2) Begin loop.
(3) If line no is a multiple of 53, then print array1 then array2. Initialize array1 and array2. Initialise an index to 0
(5) For all lines, including (if line no is a multiple of 53). Append the current line (first 66 bytes to array1[index] and the next 66 to array2[index. Increment index.
(5) Loop
(6) EOF. Vomit out whats in the arrays. (This takes care if the number of lines isn't a multiple of 53).
I agree with theNbomr. It is correct to ask what you have done so far.
Shnapper............
Is this task you be charged with something totally new.
Has the person normally responsible for this area and who is out this week, done this before.
Where I'm leading, is it possible that he already has a script that will do this?
This is a new task and not been done here before. I have been working on this and found it may not be doable with using a static "line number" as the output file will be different in size with each individual person selected. The process selects one or more students and their records will be different based on their academic history. One could have a few records, and another could have a lot making their record longer. Also, just thrown in is if a certain record is present, delete that whole page.
If I use sed 's/search string, how do I delete that whole page? Last line for that page is ********** END OF TRANSCRIPT **********
Need that page removed as they do not want it printed.
This is a new task and not been done here before. I have been working on this and found it may not be doable with using a static "line number" as the output file will be different in size with each individual person selected.
A careful look at the sample you attached will show that the end of each record is signified by
Quote:
********************* CONTINUED ON NEXT COLUMN *****************************
followed by a 0d 0c (carriage-return+formfeed) pair.
Of course within this, it has a continued on page 2 and so on.
You should probably use these as your delimiter instead of 53.
An inner loop for the "continued on page n..: and an outer loop for "continued on next column".
By the way, this looks like some old test scores that have been scanned and saved as pdf (usually) input.
If this is so, then I think you should look for packages that read 2-up pdf files and make them into single columns.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.