Yank versus control-insert formatting differences?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Yank versus control-insert formatting differences?
# 1  
Old 07-18-2011
Yank versus control-insert formatting differences?

Hello! Graduate student thrown to the sharks of unix and fortran77 here.

My basic question is this: what exactly is the difference between yank (ie "*yG for the whole file and "*p in a new file) and control-insert / shift-insert with respect to text formatting? One is vi and one is Windows, according to wikipedia, and one can get the whole file and the other leads to monotonous copy, paste, scroll, rinse, repeat. BUT, for my purposes, the way control-insert reformats the text upon pasting is different than yank, and it's something I actually want to reproduce in bulk for the rest of the file.

Some background: I needed to pare down the grid size of a csv data file to match new inputs, so I did it in a rather tedious but effective way in MATLAB using dlmwrite(fout, [datanames],'-append', 'newline','unix') within an if-loop for my parameters. The resulting file (let's call it problemchild.csv) looks like this:
1422,52,1,24.881,-88.113,0,300,293,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
1423,53,1,24.85,-87.766,0,300,293,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
and so on.

The parent data-reading program (MEGAN) refuses to read problemchild.csv, though, insisting
>>--->> WARNING in subroutine STR2INT
No digits in "^@^@^@ã6²?7 "
even though the file I made appears to be in exactly the same format, even when looking at cat -v problemchild.csv, as the larger original. I suspect because I wrote it in dlmwrite that the file is characterized as numerical, not a string, even though it looks the same. I would rather not edit the parent program, however, because it uses STR2INT in ways I'm not sure I could reproduce if I took the commands out. So, I'd like to figure out how to copy over my problemchild text into a file that will pass STR2INT. Trying to copy and paste in a quick manner (ie cat problemchild.csv >> newfile.csv OR "*yG and "*p) reproduces the same error, but control-insert and shift-insert for each line of the file produces something the parent program will actually read. Except that the problemchild file is 1800+ lines long, and I'd really prefer not to convert it manually...

I've tried to search around but I'm still pretty new at this and I haven't found much that has been helpful. I'm using VIM - Vi IMproved 6.3 (2004 June 7, compiled Jan 11 2005 10:55:42) and it's not linked to my clipboard via xterm_clipboard, if that is useful at all. I'm kind of at the end of my rope with this so any help would be appreciated. Thanks!
# 2  
Old 07-19-2011
Marshlight,
Not sure of what you meant by paring down the grid size... but here is a easy way to reformat a delimited file (this assumes your data values do not contain embedded comma's in the data, they are just used for separators).

Given your sample data, contained in file "sampledata":
1422,52,1,24.881,-88.113,0,300,293,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
1423,53,1,24.85,-87.766,0,300,293,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0

This example takes the first 5 fields and saves to a new "result" file. Note the delimiter is the comma, the printf command is used... 5 "%s" format strings are used, and you pass the first 5 fields: $1 through $5:

Code:
Code:
awk -F\, '{printf("%s,%s,%s,%s,%s\n",$1,$2,$3,$4,$5)}' samplefile > result

Result file contains:
Code:
1422,52,1,24.881,-88.113
1423,53,1,24.85,-87.766

By adjusting the number of "%s" formats and the field positions you want, you should be able to pare-down the data the way you want.
# 3  
Old 07-19-2011
Thanks for the reply! I had taken a 111x147 gridmap of the above format (I do need all the columns eventually) and shortened it to 90x97 - that's what I meant by paring down. But your instructions may be useful in the future!

After I read what I wrote, I realized it sounded crazy, so I went digging for other reasons why things might not be working. It appears that there's another file that is connected to what str2int reads, and if everything (ie gridmap definition) doesn't exactly match, it doesn't work and defaults to the error above. Not a particularly enlightening system but it gives me something to go on. In short, nevermind...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

2. Shell Programming and Scripting

insert LF and TAB for formatting

trying to insert a LF and 2 TABs for this: sed 's/<td><\/td>/<td>\n\t\t<\/td>/' infile. but, I'm not getting the syntax for inserting the LF and TABs correct (1 Reply)
Discussion started by: dba_frog
1 Replies

3. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

4. Shell Programming and Scripting

^M in yank but not in file in Vim

I am trying to visually select a section of text in vim and then substitute for it using the :%s/ sequence. First I visually select text. Then I yank using "ay. Then I type :%s/ followed by Control R and the register name, in this case a. This fills in the text I have visually selected into... (6 Replies)
Discussion started by: Enobarbus37
6 Replies

5. UNIX for Advanced & Expert Users

cpio versus cp

I am copying a file system to another one. someone suggest me use find . -print |cpio -pdmv but I think cp -r should do the same thing. Am I right? In addition, by using " find . ", I got all the file names,, why do I have to use the -print option? Thanks a lot! (1 Reply)
Discussion started by: fredao
1 Replies

6. UNIX for Dummies Questions & Answers

Yank a column in vi

I have a file which has data in columns. Is there a way to yank columns in vi? I tried searching in this forum. I did not find it. Please help me out. (2 Replies)
Discussion started by: stevelrf
2 Replies

7. UNIX for Dummies Questions & Answers

annoying vi yank word + delete all question

Hello when i try to yank word only that looks like this "$$foo$" when i stand with my curser marker on the first char ($) and do in vi : "yw" (yank word) its yanks me only the "$" char when i stand white my curser on "f" its yank's me only "foo" how can i yank all word no matter what... (4 Replies)
Discussion started by: umen
4 Replies

8. Shell Programming and Scripting

<LF> versus <CR>/<LF>

Hello, Can someone explain how to distinguish a LF character and a CR/LF character in a text file from a shell script. Thanks (1 Reply)
Discussion started by: jerardfjay
1 Replies

9. UNIX for Dummies Questions & Answers

CTRL+H versus ^? versus BACKSPACE

Hi Gurus! I recently got my shell account (HP UX v11) created by our sysadmin and am having problem deleting with the backspace key. After doing some reading, I believe I need to enter a custom "STTY..." statement in my profile. Can someone please help me with the correct "STTY" sequence... (3 Replies)
Discussion started by: alan
3 Replies

10. UNIX for Dummies Questions & Answers

yank

This is supposed to be simple to do but I am having a hard time trying to yank 1 line (yy) but creating from it 100 lines. I can do yy then keep hitting . to repeat but it doesn't make sense. I may want to create 1000 lines from the one liner. yy then 99 p doesn't work.... Thanks. I was... (5 Replies)
Discussion started by: giannicello
5 Replies
Login or Register to Ask a Question