Sponsored Content
Top Forums Shell Programming and Scripting adding the data at a specified location in a file.... Post 302250657 by divya_flora on Friday 24th of October 2008 02:18:35 AM
Old 10-24-2008
adding the data at a specified location in a file....

Hi all,
I m new to shell programming..Can anyone please guide me how to insert data at a specified location in the file..
I have a configuration file..I want to add data to it through script..I am able to do it...I get that data written at end of my configuration file..I want data to be placed at a specified location...
As,I have a header [mydata] in my configuration file..I want to place the data here...
Is it possible to do that...
Example:
My configuration file:
[global]
hello
aaa
bbbb
[share]
gghg
hnnmm
bbb
[mydata]
gggg
[printing]
cvbvbb
vbvbb
Now,I want my data to be entered after header [mydata], not at the end of Configuration file...

Thanking you...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help for Adding Three new columns in existing file from fatching data from file

not required this time (36 Replies)
Discussion started by: Sandeep_Malik
36 Replies

2. Shell Programming and Scripting

Read Write byte range/chunk of data from specific location in file

I am new to Unix so will really appreciate if someone can guide me on this. What I want to do is: Step1: Read binary file - pick first 2 bytes, convert from hex to decimal. Read the next 3 bytes as well. 2 bytes will specify the number of bytes 'n' that I want to read and write... (1 Reply)
Discussion started by: Kbenipel
1 Replies

3. Shell Programming and Scripting

Adding data in a file on same line

Hi, I have one file a.txt ,the contents of the file is A B C D E F and I have another file b.txt, the contents of the file is 1 2 3 4 5 6 now when I am using this command cat a.txt b.txt > c.txtI am getting the output as A B C D E F 1 2 3 4 5 6 but i need the output... (2 Replies)
Discussion started by: prarat
2 Replies

4. Shell Programming and Scripting

Adding the data before file extension

HI , I have a file with multiple lines like below, I need to check on column starting with #prototype if it has the .Number.txt extension do nothing else add 1.txt extension. Source data Jdbc_app_data :- sample data #prototype= sample data from test.1.txt application_id=122135... (4 Replies)
Discussion started by: gaur.deepti
4 Replies

5. Shell Programming and Scripting

Help in adding a data after a particular line of data in a file.

Hi.. I'm into a bump after trying to solve this prob.. i've a file with contents like below. <blankline> 'pgmId' : 'UNIX', 'pgmData' : 'textfile', 'author' : 'admin', ....... Now i'm trying to insert a new data after pgmId. so the final output will be... (7 Replies)
Discussion started by: arjun_arippa
7 Replies

6. Red Hat

Adding a data file

I need to add a data file, but my user account doesn't have privileges. I have connected to the oracle as sqlplus / as sysdba and it is telling me I'm connect to an idle instance. How can I connect to my database and create a data file if I don't know the passwords of any of the account that have... (1 Reply)
Discussion started by: FaSho76
1 Replies

7. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

8. Shell Programming and Scripting

Adding data from a file based on some condition

I collect data in a file in below format(Month Day Year Size) in RedHat Linux. Now i want to calculate the data size date wise. As i code shell script after long time, i forgot the features and syntax. Can anyone help me regard this please. Feb 8 2014 15 Feb 10 2014 32 Feb 10 2014 32 Feb 12... (2 Replies)
Discussion started by: makauser
2 Replies

9. Shell Programming and Scripting

Adding lines at a particular location in a file.

Hi Experts, Let us take a text file,say items.txt having the following data jar bottle gum tube cereal bag I want to add the content of items.txt to another file say #many lines not necessary ingredients #many line not necesary ingredients I want to append the data in... (3 Replies)
Discussion started by: Pradeep_1990
3 Replies

10. Shell Programming and Scripting

Adding a comment in a file next to data

Dear Gurus, I have a file which comes every day with set of data, as a part of processing i want to add a comment at the start of every line. e.g of file <PCL> 2E;"HCA";"COP Car A";"ODBS_CFG" 7C;"DD";"Doors Car D";"ODBS_CFG" 3D;"XA";"Auxiliary Car A";"ODBS_CFG" 3E;"XB";"Auxiliary... (12 Replies)
Discussion started by: guddu_12
12 Replies
ARCHIVE_WRITE(3)					   BSD Library Functions Manual 					  ARCHIVE_WRITE(3)

NAME
archive_write -- functions for creating archives LIBRARY
Streaming Archive Library (libarchive, -larchive) SYNOPSIS
#include <archive.h> DESCRIPTION
These functions provide a complete API for creating streaming archive files. The general process is to first create the struct archive object, set any desired options, initialize the archive, append entries, then close the archive and release all resources. Create archive object See archive_write_new(3). To write an archive, you must first obtain an initialized struct archive object from archive_write_new(). Enable filters and formats, configure block size and padding See archive_write_filter(3), archive_write_format(3) and archive_write_blocksize(3). You can then modify this object for the desired operations with the various archive_write_set_XXX() functions. In particular, you will need to invoke appropriate archive_write_add_XXX() and archive_write_set_XXX() functions to enable the corresponding compression and format sup- port. Set options See archive_read_set_options(3). Open archive See archive_write_open(3). Once you have prepared the struct archive object, you call archive_write_open() to actually open the archive and prepare it for writing. There are several variants of this function; the most basic expects you to provide pointers to several functions that can provide blocks of bytes from the archive. There are convenience forms that allow you to specify a filename, file descriptor, FILE * object, or a block of mem- ory from which to write the archive data. Produce archive See archive_write_header(3) and archive_write_data(3). Individual archive entries are written in a three-step process: You first initialize a struct archive_entry structure with information about the new entry. At a minimum, you should set the pathname of the entry and provide a struct stat with a valid st_mode field, which specifies the type of object and st_size field, which specifies the size of the data portion of the object. Release resources See archive_write_free(3). After all entries have been written, use the archive_write_free() function to release all resources. EXAMPLE
The following sketch illustrates basic usage of the library. In this example, the callback functions are simply wrappers around the standard open(2), write(2), and close(2) system calls. #ifdef __linux__ #define _FILE_OFFSET_BITS 64 #endif #include <sys/stat.h> #include <archive.h> #include <archive_entry.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> struct mydata { const char *name; int fd; }; int myopen(struct archive *a, void *client_data) { struct mydata *mydata = client_data; mydata->fd = open(mydata->name, O_WRONLY | O_CREAT, 0644); if (mydata->fd >= 0) return (ARCHIVE_OK); else return (ARCHIVE_FATAL); } ssize_t mywrite(struct archive *a, void *client_data, const void *buff, size_t n) { struct mydata *mydata = client_data; return (write(mydata->fd, buff, n)); } int myclose(struct archive *a, void *client_data) { struct mydata *mydata = client_data; if (mydata->fd > 0) close(mydata->fd); return (0); } void write_archive(const char *outname, const char **filename) { struct mydata *mydata = malloc(sizeof(struct mydata)); struct archive *a; struct archive_entry *entry; struct stat st; char buff[8192]; int len; int fd; a = archive_write_new(); mydata->name = outname; archive_write_add_filter_gzip(a); archive_write_set_format_ustar(a); archive_write_open(a, mydata, myopen, mywrite, myclose); while (*filename) { stat(*filename, &st); entry = archive_entry_new(); archive_entry_copy_stat(entry, &st); archive_entry_set_pathname(entry, *filename); archive_write_header(a, entry); if ((fd = open(*filename, O_RDONLY)) != -1) { len = read(fd, buff, sizeof(buff)); while ( len > 0 ) { archive_write_data(a, buff, len); len = read(fd, buff, sizeof(buff)); } close(fd); } archive_entry_free(entry); filename++; } archive_write_free(a); } int main(int argc, const char **argv) { const char *outname; argv++; outname = argv++; write_archive(outname, argv); return 0; } SEE ALSO
tar(1), libarchive(3), archive_write_set_options(3), cpio(5), mtree(5), tar(5) HISTORY
The libarchive library first appeared in FreeBSD 5.3. AUTHORS
The libarchive library was written by Tim Kientzle <kientzle@acm.org>. BUGS
There are many peculiar bugs in historic tar implementations that may cause certain programs to reject archives written by this library. For example, several historic implementations calculated header checksums incorrectly and will thus reject valid archives; GNU tar does not fully support pax interchange format; some old tar implementations required specific field terminations. The default pax interchange format eliminates most of the historic tar limitations and provides a generic key/value attribute facility for vendor-defined extensions. One oversight in POSIX is the failure to provide a standard attribute for large device numbers. This library uses ``SCHILY.devminor'' and ``SCHILY.devmajor'' for device numbers that exceed the range supported by the backwards-compatible ustar header. These keys are compatible with Joerg Schilling's star archiver. Other implementations may not recognize these keys and will thus be unable to correctly restore device nodes with large device numbers from archives created by this library. BSD
February 2, 2012 BSD
All times are GMT -4. The time now is 09:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy