LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2012, 08:09 AM   #1
Shnapper
LQ Newbie
 
Registered: Aug 2012
Posts: 6

Rep: Reputation: Disabled
Need Help with Shell Scripting


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.

Thanks.
 
Old 08-21-2012, 08:12 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 ?
 
Old 08-21-2012, 08:17 AM   #3
Shnapper
LQ Newbie
 
Registered: Aug 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.

Thanks.
 
Old 08-21-2012, 08:22 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
without seeing the sample input file i am assuming the awk command is probably what you want [quick-and-dirty]:
Code:
awk '{print $1}' file-in.txt > file-out.txt && awk '{print $2}' file-in.txt >> file-out.txt
> redirects output to a file and >> appends output to a file.

Last edited by schneidz; 08-21-2012 at 08:26 AM.
 
Old 08-21-2012, 08:40 AM   #5
Shnapper
LQ Newbie
 
Registered: Aug 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks for the help.

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.
Attached Files
File Type: txt shrtrtc_368192_sample.lis.txt (8.1 KB, 34 views)
 
Old 08-21-2012, 09:10 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
awk is a program used for data extraction. now that i see your sample input i think that the cut command would work better here.

still not sure what the after picture is supposed to look like but play around with cut and see if you can get the desired output.
 
Old 08-21-2012, 10:18 AM   #7
Shnapper
LQ Newbie
 
Registered: Aug 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Can you provide sample coding for using cut?

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.


Thanks.
 
Old 08-21-2012, 11:07 AM   #8
nittmann
LQ Newbie
 
Registered: Aug 2012
Posts: 9

Rep: Reputation: 0
deleted

Last edited by nittmann; 08-23-2012 at 12:13 AM.
 
Old 08-21-2012, 12:26 PM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

--- rod.

Last edited by theNbomr; 08-21-2012 at 12:30 PM.
 
Old 08-21-2012, 11:27 PM   #10
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
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.

OK
 
Old 08-22-2012, 12:16 AM   #11
Dafydd
Member
 
Registered: Oct 2008
Posts: 344

Rep: Reputation: 29
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?
 
Old 08-22-2012, 08:14 AM   #12
Shnapper
LQ Newbie
 
Registered: Aug 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-22-2012, 08:32 AM   #13
Shnapper
LQ Newbie
 
Registered: Aug 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-25-2012, 08:13 PM   #14
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
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.

OK

Last edited by AnanthaP; 08-25-2012 at 08:17 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-26-2008 11:50 PM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 08:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 PM.

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