Sponsored Content
Top Forums Shell Programming and Scripting How do I insert a line in the middle of a file in BASH? Post 302245153 by phenom on Thursday 9th of October 2008 01:04:37 PM
Old 10-09-2008
I have a $(whoami) in the line to be inserted and

sed '6a\
text_to_insert
'

is not recognizing it. it inserts $(whoami) instead of the username
any ideas??
 

10 More Discussions You Might Find Interesting

1. Programming

how to insert and delete characters in the middle of file

I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end. Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies

2. Shell Programming and Scripting

awk insert character in the middle of a line

I'm trying to insert a single character at position 11 in everyline of a file. My input file looks like this: 456781 ~Y~12345 456782 ~N~12300 and I want my output to look like this: 45678~1 ~Y~12345 45678~2 ~N~12300 I tried the following awk code, but it's not working:... (3 Replies)
Discussion started by: mmarino
3 Replies

3. Shell Programming and Scripting

insert text into the middle of a original file

how do u insert text into a specific place in a file, say the middle for example, without changing the name for that file (1 Reply)
Discussion started by: mopimp
1 Replies

4. Shell Programming and Scripting

How to insert text into first line of the file and middle of the file?

Script 1 Pre-requisites Create a file with x amount of lines in it, the content of your choice. Write a script that takes two arguments. The first being a line of text, the second being your newly created file. The script should take the first argument and insert it into the very top (the... (3 Replies)
Discussion started by: ali hussain
3 Replies

5. Shell Programming and Scripting

How to insert the 1st arg into the middle of the file

I wrote a script like #!/bin/bash echo $1 > temp cat $2 >> temp mv temp $2 now I have problem appending the above script(only using bash shell) so that it now inserts the first argument into the middle of the file. I have tried using $(('wc -l < file' / 2 )) but invain so could any one... (4 Replies)
Discussion started by: boris
4 Replies

6. Shell Programming and Scripting

insert one file into middle of another file

how to insert one file into another file not by concatenating as usual done. file1 A B C D E F G H I J K L file2 23455 33444 33334 33345 Output shud be 23455 A B C D (4 Replies)
Discussion started by: cdfd123
4 Replies

7. Shell Programming and Scripting

insert text in the middle of a file

I want to insert a text into the middle of a file (3 Replies)
Discussion started by: relle
3 Replies

8. UNIX for Dummies Questions & Answers

How to insert text in the middle of a file

Hey guys, how do we take a line of text as an argument from a user and then insert it in the middle of a file irrespective of the number of lines in the file. I am trying to do this without SED or AWK. Inserting it in the beginning and at the end is easy, but i am trying to accomplish inserting... (6 Replies)
Discussion started by: kartikkumar84@g
6 Replies

9. Shell Programming and Scripting

How to insert text in the middle of a file?

Hi, So far i've made a script that takes two argument, 1st is the contents and the 2nd is the named file. At the moment i've managed to insert new contents as a new line at the top, but i want to ask how can you insert contents in the middle of the file? Source Code #!/bin/bash #Write... (3 Replies)
Discussion started by: zen10
3 Replies

10. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies
COM_ERR(3)						   BSD Library Functions Manual 						COM_ERR(3)

NAME
com_err, com_err_va, error_message, error_table_name, init_error_table, set_com_err_hook, reset_com_err_hook, add_to_error_table, initialize_error_table_r free_error_table, com_right -- common error display library LIBRARY
Common Error Library (libcom_err, -lcom_err) SYNOPSIS
#include <stdio.h> #include <stdarg.h> #include <krb5/com_err.h> #include "XXX_err.h" typedef void (*errf)(const char *, long, const char *, ...); void com_err(const char *whoami, long code, const char *format, ...); void com_err_va(const char *whoami, long code, const char *format, ...); const char * error_message(long code); const char * error_table_name(int num); int init_error_table(const char **msgs, long base, int count); errf set_com_err_hook(errf func); errf reset_com_err_hook(); void add_to_error_table(struct et_list *new_table); void initialize_error_table_r(struct et_list **et_list, const char **msgs, int base, long count); void free_error_table(struct et_list *); const char * com_right(struct et_list *list, long, code"); DESCRIPTION
The com_err library provides a common error-reporting mechanism for defining and accessing error codes and descriptions for application soft- ware packages. Error descriptions are defined in a table and error codes are used to index the table. The error table, the descriptions and the error codes are generated using compile_et(1). The error table is registered with the com_err library by calling its initialisation function defined in its header file. The initialisation function is generally defined as initialize_<name>_error_table(), where name is the name of the error table. If a thread-safe version of the library is needed initialize_<name>_error_table_r() that internally calls initialize_error_table_r() instead be used. Any variable which is to contain an error code should be declared <name>_error_number where name is the name of the error table. FUNCTIONS
The following functions are available to the application developer: com_err(whoami, code, format, ...) Displays an error message on standard error composed of the whoami string, which should specify the program name, followed by an error message generated from code, and a string produced using the printf(3) format string and any following arguments. If format is NULL, the formatted message will not be printed. The argument format may not be omitted. com_err_va(whoami, code, format, va_list args) This routine provides an interface, equivalent to com_err(), which may be used by higher-level variadic functions (functions which accept variable numbers of arguments). error_message(code) Returns the character string error message associate with code. If code is associated with an unknown error table, or if code is associated with a known error table but is not in the table, a string of the form `Unknown code XXXX NN' is returned, where XXXX is the error table name produced by reversing the compaction performed on the error table number implied by that error code, and NN is the offset from that base value. Although this routine is available for use when needed, its use should be left to circumstances which render com_err() unusable. com_right() returns the error string just like com_err but in a thread-safe way. error_table_name(num) Convert a machine-independent error table number num into an error table name. init_error_table(msgs, base, count) Initialise the internal error table with the array of character string error messages in msgs of length count. The error codes are assigned incrementally from base. This function is useful for using the error-reporting mechanism with custom error tables that have not been generated with compile_et(1). Although this routine is available for use when needed, its use should be restricted. initialize_error_table_r() initialize the et_list in the same way as init_error_table(), but in a thread-safe way. set_com_err_hook(func) Provides a hook into the com_err library to allow the routine func to be dynamically substituted for com_err(). After set_com_err_hook() has been called, calls to com_err() will turn into calls to the new hook routine. This function is intended to be used in daemons to use a routine which calls syslog(3), or in a window system application to pop up a dialogue box. reset_com_err_hook() Turns off the hook set in set_com_err_hook(). add_to_error_table(new_table) Add the error table, its messages strings and error codes in new_table to the internal error table. EXAMPLES
The following is an example using the table defined in compile_et(1): #include <stdio.h> #include <stdarg.h> #include <syslog.h> #include "test_err.h" void hook(const char *whoami, long code, const char *format, va_list args) { char buffer[BUFSIZ]; static int initialized = 0; if (!initialized) { openlog(whoami, LOG_NOWAIT, LOG_DAEMON); initialized = 1; } vsprintf(buffer, format, args); syslog(LOG_ERR, "%s %s", error_message(code), buffer); } int main(int argc, char *argv[]) { char *whoami = argv[0]; initialize_test_error_table(); com_err(whoami, TEST_INVAL, "before hook"); set_com_err_hook(hook); com_err(whoami, TEST_IO, "after hook"); return (0); } SEE ALSO
compile_et(1) BSD
July 7, 2005 BSD
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy