Difficult problem: Complex text file manipulation in bash script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difficult problem: Complex text file manipulation in bash script.
# 8  
Old 09-20-2011
Define what you mean by 'moving', then. I'm assuming you don't mean mv oldfile newfile.
# 9  
Old 09-20-2011
Move around as in, moving around in a text document, adding for example the letter "a" on the 2nd line, 4th space. Interactively moving around the document and putting text in certain places with a bash script.
# 10  
Old 09-21-2011
Hi.

Editor emacs has a picture mode:
Quote:
PictureMode

M-x picture-mode is great if you want to do some ASCII-art, or while drawing some kind of diagram och technical sketch. When this mode is enabled it let you move around freely using the cursor keys, for example, moving up or down will move up or down to the same column as on the previous line, regardless if there were some information there before or not (i.e. it will insert the necessary spaces).

-- more at EmacsWiki: Picture Mode
and an artist mode:
Quote:
ArtistMode

Artist is an Emacs lisp package that allows you to draw lines, rectangles, squares, poly-lines, ellipses and circles by using your mouse and/or keyboard. The shapes are made up with the ascii characters |, -, / and \.

more at EmacsWiki: Artist Mode
and possibly others.

Because emacs edits files, it saves what you see on the screen.

It isn't along the lines of a script, but it looks like you are implementing this kind of thing in a script. Educational certainly, but perhaps not efficacious.

Otherwise, lots of tput cup commands and codes might help with cursor motion. See also ncurses, and language-specific ncurses interface packages, e.g.:
Code:
libcurses-perl - Curses interface for Perl

Best wishes ... cheers, drl
# 11  
Old 09-21-2011
Thank you so much for your reply.

But unfortunately thats not what I was looking for. Emacs picture mode doesn't use ANSI block characters for pictures.

Let me try my best to give you a picture of what I'm trying to do. Once again I'm sorry for the essay thats coming up.

I programmed a rather large library of script functions to deal with input, displaying ANSI block graphics, playing sounds, and refining the terminal and so on. I also designed a file format for displaying ANSI block characters in a complete group onto the screen.

The library is completely working. Graphics display properly, I can save a graphics file, and load the image on to terminal. Sound properly plays sequences of notes, etc.

Now here is where my problem arises. I hate designing graphics files for my library. I have to manually type in each ANSI escape code to make an image, and its extremely hard to make an image. So I decided to write an application to edit the ANSI graphic file images.

The program works, I set up the interface and painting works properly. BUT! I need to find a way to save the blocks on the screen into a file. This is what I did so far: I set it so whenever you paint onto the screen, it saves to a file. That works, but the problem is, the file isn't properly formatted because if everything thats painted on the screen, is saved in a file not formatted, in a sequential order in a line.

So I'm asking if theres a way to navigate through the file with commands and add text, etc. so I can implement it in my paint program.
# 12  
Old 09-21-2011
You probably going to be best off implementing these functions in you own program - Id imagine you would like to be able to select a rectangle and nudge up/down left/right, copy/paste and even perhaps rotate clockwise/anti-clockwise. The processing involved in writing a file and calling external commands like sed/awk to do this sort of thing is going to add too much lag to your interface.

I'd assume you have an array or the like for each X,Y character so it should just involve simple operations on this followed by a repaint screen function to get the job done.

Last edited by Chubler_XL; 09-21-2011 at 11:12 PM..
# 13  
Old 09-21-2011
I've already done that. I created the a temporary file to hold all paint routines. When the user wants to save the file, the temporary file is exported. Problem is formatting the file so it displays each line of block characters correctly, instead of in a straight line.

I also have X Y variable that is used to help redraw to interface.

I'm using Bash by the way.

Last edited by tinman47; 09-21-2011 at 11:15 PM..
# 14  
Old 09-21-2011
Sorry I re-read my message and I wasn't really clear on what I was getting at, so I updated it, but that process took longer that I expected due to interuptions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Complex Bash Script

I have an FTP server with thousands of Invoices. All Invoices are in a folder called /volume1/MBSInvoices/ Monthly invoices are added to that folder every month. Here is a sample filename of the Invoices: invoice_1_20170101_10010052_10020052_10030052_JOHNDOE.pdf the Account ID is the... (6 Replies)
Discussion started by: badr777
6 Replies

2. Shell Programming and Scripting

Text manipulation with sed/awk in a bash script

Guys, I have a variable in a script that I want to transform to into something else Im hoping you guys can help. It doesn't have to use sed/awk but I figured these would be the simplest. DATE=20160120 I'd like to transform $DATE into "01-20-16" and move it into a new variable called... (8 Replies)
Discussion started by: dendenyc
8 Replies

3. Shell Programming and Scripting

Bash script to replace text file from a lookup file

Hi. I need assistance with the replacing of text into a specific file via a bash script. My bash script, once run, currently provides a menu of computer names to choose.The script copies onto my system various files, depending what computer was selected in the menu.This is working OK. Now, I... (1 Reply)
Discussion started by: jonesn2000
1 Replies

4. Shell Programming and Scripting

Complex text parsing with speed/performance problem (awk solution?)

I have 1.6 GB (and growing) of files with needed data between the 11th and 34th line (inclusive) of the second column of comma delimited files. There is also a lot of stray white space in the file that needs to be trimmed. They have DOS-like end of lines. I need to transpose the 11th through... (13 Replies)
Discussion started by: Michael Stora
13 Replies

5. Shell Programming and Scripting

Bash - file manipulation

I need to change a file like this: John Smith;http://www.profile1.com John Smith;http://www.profile2.com Frank Olsen;http://www.profile3.com Frank Olsen;http://www.profile4.com Into: John Smith;http://www.profile1.com;http://www.profile2.com Frank... (2 Replies)
Discussion started by: locoroco
2 Replies

6. Shell Programming and Scripting

Been working since 25+ hrs: Bash Script to rename files supposedly direct but difficult to execute

:wall::wall::wall: Hi I have horrible script below, need help in renaming ls -l output into new filename format: Desired output: cp -pv original_path/.* newDirectory/owner_of_file.%dd%mm%y.file_extension.first_8_characters_of_original_filename localuser@localuser:~ vi... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

7. Shell Programming and Scripting

Please help. Complicated text file manipulation problem

Let me try my best to give you a picture of what I'm trying to do. Once again I'm sorry for the essay thats coming up. I programmed a rather large library of script functions to deal with input, displaying ANSI block graphics, playing sounds, and refining the terminal and so on. I also designed... (8 Replies)
Discussion started by: tinman47
8 Replies

8. Shell Programming and Scripting

AWK manipulation in bash script

EDIT: This has been SOLVED. Thanks! Greetings everyone, I've posted a few threads with some quick help questions, and this is another one of those. I can't post enough gratitude for those much more knowledgeable than myself who are willing to give good advice for my minor issues. Now,... (2 Replies)
Discussion started by: Eblue562
2 Replies

9. Shell Programming and Scripting

Shell script text file manipulation.

Hello, I have mysql binary file which logs all the database queries and i to insert all queries log in to database. First i coverted binary file to text file. and start playing with it. Text file contains following queries, some samples are, SET INSERT_ID=1; INSERT INTO test... (0 Replies)
Discussion started by: mirfan
0 Replies

10. Shell Programming and Scripting

Bash file manipulation help

Hello, I'm writing a bash script and I have a question. Here's what I'm doing: I have a file called inv.dat which contains the following: B102:Action Figure - Teacher:79 B103:Bike - Purple:23 B104:Baseball:25 B105:Cricket Bat:15 B101:Action Figure - Fireman:15 B100:Flame-Thrower:25 ... (2 Replies)
Discussion started by: netmaster
2 Replies
Login or Register to Ask a Question