Sponsored Content
Top Forums Shell Programming and Scripting Bash - Appending to specific line in file Post 302798037 by Don Cragun on Tuesday 23rd of April 2013 04:36:16 PM
Old 04-23-2013
I apologize. In my last posting, the awk program I supplied was missing a closing brace. I should have pasted it in the form I used when I tested it instead of converting it back to a 1-liner. Try the following awk script (but use /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk instead of awk if you're using a Solaris/SunOS system):
Code:
awk -F"|" '
{       if($1==factor) {
                print $0 FS trial
                found=1
        } else print
}
END{    if(! found) print factor FS trial
}' factor="3,6" trial="YES,18,1.635" < file > file.new

And, no. Changing the field separator from "|" to ":" will not make any real difference. This script will add new trial results to the line in file that has the given factors (or add a new line if the given factors are not already in file); not replace existing trial results. It will never replace existing trial information when adding a new trial. You just need to move or copy file.new to file after each trial is successfully added.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading specific contents from a file and appending it to another file

Hi, I need to write a shell script (ksh) to read contents starting at a specific location from one file and append the contents at specific location in another file. Please find below the contents of the source file that I need to read the contents from, File 1 -----# more... (5 Replies)
Discussion started by: dnicky
5 Replies

2. Shell Programming and Scripting

Appending the line number and a seperator to each line of a file ?

Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one. I want to basically append to each line in a file a delimiter character and the line's line number e.g Change the file from :- aaaaaa bbbbbb cccccc to:- aaaaaa;1 bbbbbb;2 cccccc;3 I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies

3. Shell Programming and Scripting

Appending a column in one file to the corresponding line in a second

It appears that this has been asked and answered in similar fashions previously, but I am still unsure how to approach this. I have two files containing user information: fileA ttim:/home/ttim:Tiny Tim:632 ppinto:/home/ppinto:Pam Pinto:633 fileB ttim:xkfgjkd*&#^jhdfh... (3 Replies)
Discussion started by: suzannef
3 Replies

4. Shell Programming and Scripting

How to read the value from a specific line and column BASH

Hi All, I have the same problem as the one posted in https://www.unix.com/shell-programming-scripting/96097-how-read-value-specific-line-column-csh-variable.html but I'm using bash. Can anyone tell me how I have to modify the code to make it bash compatible? eval `awk 'NR==3{print "set... (5 Replies)
Discussion started by: f_o_555
5 Replies

5. UNIX Desktop Questions & Answers

Appending file extensions to filenames in bash scripts

Hi Suppose I have a variable called filename and it it contains the name of a file. I then would like to append an extension to that filename. The filename currently has no extensions. How do I do this? Thanks (11 Replies)
Discussion started by: ladyAnne
11 Replies

6. UNIX for Advanced & Expert Users

Appending # to the start of specific line in a properties file

Hi, I have the following file, ABC.txt: ABC=123 DEF=234 FGH=345 Based on my validation and conditional processing it is observed that i need to comment or append # before DEF=234 so the same file ABC.txt should look as follows ABC=123 #DEF=234 FGH=345 Sorry if its a... (6 Replies)
Discussion started by: mihirvora16
6 Replies

7. UNIX for Dummies Questions & Answers

Comparing to specific line in file bash script

Hi, I have a value stored in x and I need to compare it to the numbers in every other line of a file. The file contains alternating lines of numbers and letters: aaaa1111 AAAAAAAA bbbb2222 BBBBBBBB cccc3333 CCCCCCCC I need to compare x to the numbers in every other line without the... (2 Replies)
Discussion started by: ShiGua
2 Replies

8. UNIX for Advanced & Expert Users

Appending a files contents to the end of a specific file name in several directories

Here is my dir structure: /tmp/dave/myappend.txt /tmp/dave/dir1/test.txt /tmp/dave/dir2/test.txt /tmp/dave/dir3/test.txt /tmp/dave/dir4/test.txt I want to append the contents of myappend.txt to the end of each file with the name "test.txt" in all dirs in /tmp/dave/ I have tried this:... (2 Replies)
Discussion started by: bigd213
2 Replies

9. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

10. Shell Programming and Scripting

Appending content of a file to another file before a specific character

Hi there, i've got a file with this content $ cat file1 Matt Mar The other file has the same number of lines with this content: $ cat file2 20404=767294 23450=32427 is there a way with either using sed, awk or paste to insert the content of file1 before the "=" character? So... (3 Replies)
Discussion started by: nms
3 Replies
TRIAL(1)																  TRIAL(1)

NAME
trial - run unit tests SYNOPSIS
trial [options] [[file|package|module|TestCase|testmethod]...] trial --help DESCRIPTION
trial loads and executes a suite of unit tests, obtained from modules, packages and files listed on the command line. trial will take either filenames or fully qualified Python names as arguments. Thus 'trial myproject/foo.py', 'trial myproject.foo' and 'trial myproject.foo.SomeTestCase.test_method' are all valid ways to invoke trial. -b, --debug Run the tests in the Python debugger. Also does post-mortem debugging on exceptions. Will load '.pdbrc' from current directory if it exists. -B, --debug-stacktraces Report Deferred creation and callback stack traces --coverage Generate coverage information in _trial_temp/coverage/. Requires Python 2.3 or higher. --disablegc Disable the garbage collector. I don't know why this is in trial. -x, --extra Add an extra argument. (This is a hack necessary for interfacing with emacs's `gud'.) -e, --rterrors Print tracebacks to standard output as soon as they occur --force-gc Run gc.collect() before and after each test case. This can be used to isolate errors that occur when objects get collected. This option would be the default, except it makes tests run about ten times slower. -h, --help Print a usage message to standard output, then exit. --help-reporters Print a list of valid reporters to standard output, then exit. --help-reactors List the names of possibly available reactors. -l, --logfile <logfile> Direct the log to a different file. The default file is 'test.log'. <logfile> is relative to _trial_temp. -n, --dry-run Go through all the tests and make them pass without running. -N, --no-recurse By default, trial recurses through packages to find every module inside every subpackage. Unless, that is, you specify this option. --nopm Don't automatically jump into debugger for post-mortem analysis of exceptions. Only usable in conjunction with --debug. --profile Run tests under the Python profiler. -r, --reactor <reactor> Choose which reactor to use. See --help-reactors for a list. --recursionlimit Set Python's recursion limit. See sys.setrecursionlimit() --reporter Select the reporter to use for Trial's output. Use the --help-reporters option to see a list of valid reporters. --spew Print an insanely verbose log of everything that happens. Useful when debugging freezes or locks in complex code. --tbformat <format> Format to display tracebacks with. Acceptable values are 'default', 'brief' and 'verbose'. 'brief' produces tracebacks that play nicely with Emacs' GUD. --temp-directory <directory> WARNING: Do not use this options unless you know what you are doing. By default, trial creates a directory called _trial_temp under the current working directory. When trial runs, it first deletes this directory, then creates it, then changes into the directory to run the tests. The log file and any coverage files are stored here. Use this option if you wish to have trial run in a directory other than _trial_temp. Be warned, trial will delete the directory before re-creating it. --testmodule <filename> Ask trial to look into <filename> and run any tests specified using the Emacs-style buffer variable 'test-case-name'. --unclean-warnings As of Twisted 8.0, trial will report an error if the reactor is left unclean at the end of the test. This option is provided to assist in migrating from Twisted 2.5 to Twisted 8.0 and later. Enabling this option will turn the errors into warnings. -u, --until-failure Keep looping the tests until one of them raises an error or a failure. This is particularly useful for reproducing intermittent failures. --version Prints the Twisted version number and exit. --without-module <modulenames> Simulate the lack of the specified comma-separated list of modules. This makes it look like the modules are not present in the sys- tem, causing tests to check the behavior for that configuration. -z, --random [<seed>] Run the tests in random order using the specified seed. AUTHOR
Written by Jonathan M. Lange REPORTING BUGS
To report a bug, visit http://twistedmatrix.com/bugs/ COPYRIGHT
Copyright (C) 2003-2008 Twisted Matrix Laboratories This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. Oct 2007 TRIAL(1)
All times are GMT -4. The time now is 12:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy