text-processing

How to append to the lines with fewer columns in a tab separated text file?

孤街醉人 提交于 2019-12-13 08:19:46
问题 I have a tab separated text file. Some rows have 10 columns and some rows have 11 columns. I want to add an extra column to the last of 10 column rows with the value 0. How can i do this? 回答1: Since you have mentioned append, you can awk as below awk -F $'\t' 'BEGIN {OFS = FS} NF==10{$0=$0"0"}1' input-file The -F $'\t' takes care of the tab-separation part, BEGIN {OFS = FS} for setting the output field separation. The NF==10 looks only for the lines having only 10 records and the {$0=$0"0"}1

Batch script that replaces static string in file with filename

ぐ巨炮叔叔 提交于 2019-12-13 04:16:07
问题 This question was migrated from Unix & Linux Stack Exchange because it can be answered on Stack Overflow. Migrated last year . I have 3000 files in c:\data\ , and I need to replace a static string in each of them with the name of the file. For example, in the file 12345678.txt there will be some records along with the string 99999999 , and I want to replace 99999999 with the filename 12345678 . How can I do this using a batch script? 回答1: try this, replace_string="99999999" for f in *.txt; do

Processing lines of text file between two marker lines

Deadly 提交于 2019-12-13 02:24:23
问题 My code processes lines read from a text file (see "Text Processing Details" at end). I need to amend my code so that it carries out the same task, but only with words in between certain points. Code should not bother about this text. Skip it. *****This is the marker to say where to start working with text. Don't do anything until after these last three asterisks.>*** Work with all of the code in this section *****Stop working with the text when the first three asterisks are seen***** Code

Blurry text when generating and printing an ID card

最后都变了- 提交于 2019-12-12 17:54:12
问题 I am generating ID cards via .NET and I am having a problem where the dynamic text I insert appears so blurry that I have to use a bold font for it to be begrudgingly accepted. What I'm currently doing: Grab the image "frame". Grab the employee's photograph. Merge them. Create a new bitmap from the generated image. Add two sets of text on top of the bitmap (FontBrush color set to Black). Save the image in PNG and with the highest quality I can get. Is there something to be done when

remove “empty” lines from a text file shell script

不羁的心 提交于 2019-12-11 13:19:52
问题 I have a set of output files and some are as below: 133 0.00295 nurse merit respect muslim 134 0.00292 high dangerous reassure full 135 0.00048 136 0.0039 experience darren 137 0.00097 _ _param_ui_control_scripts_save _param_pattern_value 138 0.00292 find director And I want to get the following file: 133 0.00295 nurse merit respect muslim 134 0.00292 high dangerous reassure full 136 0.0039 experience darren 137 0.00097 _ _param_ui_control_scripts_save _param_pattern_value 138 0.00292 find

Convert year-month string column into quarterly bins

痴心易碎 提交于 2019-12-11 12:25:51
问题 I am currently working with a large phenology data set, where there are multiple observations of trees for a given month. I want to assign these observations into three month clusters or bins. I am currently using the following code: Cluster.GN <- ifelse(Master.feed.parts.gn$yr.mo=="2007.1", 1, ifelse(Master.feed.parts.gn$yr.mo=="2007.11", 1,.... ifelse(Master.feed.parts.gn$yr.mo=="2014.05", 17, NA) This code works, but it is very cumbersome as there are over 50 months. I have had trouble

Compare columns in two text files and match lines

会有一股神秘感。 提交于 2019-12-11 11:58:20
问题 I want to compare the second column (delimited by a whitespace) in file1: n01443537/n01443537_481.JPEG n01443537 n01629819/n01629819_420.JPEG n01629819 n02883205/n02883205_461.JPEG n02883205 With the second column (delimited by a whitespace) in file2: val_8447.JPEG n09256479 val_68.JPEG n01443537 val_1054.JPEG n01629819 val_1542.JPEG n02883205 val_8480.JPEG n03089624 If there is a match, I would like to print out the corresponding line of file2. Desired output in this example: val_68.JPEG

Remove quotes holding 2 words and remove comma between them

北战南征 提交于 2019-12-11 08:12:54
问题 Following up on Python to replace a symbol between between 2 words in a quote Extended input and expected output: trying to replace comma between 2 words Durango and PC in the second line by & and then remove the quotes " as well. Same for third line with Orbis and PC and 4th line has 2 word combos in quotes that I would like to process "AAA - Character Tech, SOF - UPIs","Durango, Orbis, PC" I would like to retain the rest of the lines using Python. INPUT 2,SIN-Rendering,Core Tech - Rendering

How to use pyparsing Group with SkipTo for a file parsing?

折月煮酒 提交于 2019-12-11 06:14:19
问题 When I used pyparsing SkipTo together with other parser, the file parsing seems hang. unexpected = pp.SkipTo(pp.LineEnd())('unexpected*') rules = pp.Group(predefined_parser) | unexpected parser = pp.Dict(pp.OneOrMore(rules) parser.ignore('*' + pp.restOfLine) parser.parseFile(filename, True) I turned on setDebug, here's the debug message. Any insights is highly appreciated. Match Dict:([{Group:({Combine:({"something" W:(_) Combine:({W:(ABCD...) [W:(0123...)]}) W:(_) {"sth1" | "sth2"}})

Searching for a word in a grid

浪子不回头ぞ 提交于 2019-12-11 05:48:21
问题 I'm trying to write a function that takes a square grid of letters and given a word to find from a list of words, it searches for it horizontally, vertically or diagonally (also looking backwards in each case). I've tried writing this function in various ways with no success so was wondering if my general algorithm sounded ok and implementable. Return co-ordinates for everywhere the first letter of the word occurs so something like [row,col] = find(grid==words(2)) with words being the list of