Sponsored Content
Top Forums Shell Programming and Scripting filling in strings in a template file using awk Post 302607084 by ida1215 on Tuesday 13th of March 2012 01:56:52 PM
Old 03-13-2012
filling in strings in a template file using awk

Hi all,

I have a template form to fill in for quite a number of files and I want to automate the filling-in process. the concept seemed to be simple but i cant get it work. the template form is a text file containing the information below:

File Name:
Date Created:
Contents:

I need to fill in the File Name section and so if I read the individual files, it will insert the corresponding information to the template. my desired output will be something like:

Code:
if i read file1.xyz, it will generate a form named file1.txt containing the information:

File Name: file1.xyz
Date Created:
Contents:

and so on..

Many thanks in advance.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info. Thanks in advance. I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified... (4 Replies)
Discussion started by: sp3arsy
4 Replies

2. Shell Programming and Scripting

Get data from file using awk within strings.

i am having the text data file as below. Processing 1 a 111111 b c d e f Processing 2 a b 222222 c erorr d e f Processing 3 a b 3333 (1 Reply)
Discussion started by: expert
1 Replies

3. Programming

How to replace the complex strings from a file using sed or awk?

Dear All, I am having a requirement to find the difference between 2 files and generate a discrepancy report out of it as an html page. I prefer using diff -y file1 file2 since it gives user friendly layout to know any discrepancy in the record and unique records among the 2 file. Here's how it... (12 Replies)
Discussion started by: Badhrish
12 Replies

4. Shell Programming and Scripting

Bash/awk and for loop to create a template

Source File: google.cz http://czechrepublic.google.com/ http://czechrepublic.google.cz http://czechrepublic.google.com/ http://brno.google.cz http://brno.google.com/ Fail Code root@arisvm ~/g] $ cat trya rm -f ss for i in a.txt do #b=`cat $i|awk '{print $1}'` #c=`cat $i|awk '{print... (4 Replies)
Discussion started by: invinzin21
4 Replies

5. Shell Programming and Scripting

Inputing info from a CSV file and filling a template file

Hi, I have a .csv file that contains a variety of fields for 60 clients: USERNAME, PASSWORD, and COMMENTS. I have a template file which contains a great deal of data for each client and has the fields USERNAME, PASSWORD, and COMMENTS that has to be filled with the values of USERNAME,... (1 Reply)
Discussion started by: mojoman
1 Replies

6. Shell Programming and Scripting

Filling in the missing data point by awk

I am learning AWK by trying out examples whenever I need a specific conversion. I would like to edit the 'before.txt' so that all the missing data points between 140-150 are added and shown as 0. before.txt 145 2 148 13 149 17 to below, 140 0 141 0 142 0 143 0 144 0 145 2 146 0... (5 Replies)
Discussion started by: numareica
5 Replies

7. Shell Programming and Scripting

Relocation strings using awk/sed from a index file

Hi All, I'd always appreciate all helps from this website. I would like to relocate strings based on the index number from an index file. Index numbers are shown on the first column in the index file (index.txt) and I would like to relocate "path" based on index numbers. Paths are placed... (11 Replies)
Discussion started by: jypark22
11 Replies

8. Shell Programming and Scripting

Merge strings from a file into a template

I am preparing a morphological grammar of Marathi to be placed in open-source. I have two files. The first file called Adverbs contains a whole list of words, one word per line A sample is given below: आधी इतक इतपत उलट एवढ ऐवजी कड कडनं कडल कडील कडून कडे करता करिता खाल (2 Replies)
Discussion started by: gimley
2 Replies

9. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

10. UNIX for Beginners Questions & Answers

(g)awk: Matching strings from one file in another file between two strings

Hello all, I can get close to what I am looking for but cannot seem to hit it exactly and was wondering if I could get your help. I have the following sample from textfile with many thousands of lines: File 1 PS001,001 HLK PS002,004 L<G PS004,002 XNN PS004,006 BVX PS004,006 ZBX=... (7 Replies)
Discussion started by: jvoot
7 Replies
Test::File::Contents(3pm)				User Contributed Perl Documentation				 Test::File::Contents(3pm)

Name
       Test::File::Contents - Test routines for examining the contents of files

Synopsis
	 use Test::File::Contents;

	 file_contents_eq	  $file,  $string,  $description;
	 file_contents_eq_or_diff $file,  $string,  $description;
	 file_contents_like	  $file,  qr/foo/,  $description;
	 file_md5sum_is 	  $file,  $md5sum,  $description;
	 files_eq		  $file1, $file2,   $description;
	 files_eq_or_diff	  $file1, $file2,   $description;

Description
       Got an app that generates files? Then you need to test those files to make sure that their contents are correct. This module makes that
       easy. Use its test functions to make sure that the contents of files are exactly what you expect them to be.

Interface
   Options
       These test functions take an optional hash reference of options which may include one or more of these options:

       "encoding"
	   The encoding in which the file is encoded. This will be used in an I/O layer to read in the file, so that it can be properly decoded to
	   Perl's internal representation. Examples include "UTF-8", "iso-8859-3", and "cp1252". See Encode::Supported for a list of supported
	   encodings. May also be specified as a layer, such as ":utf8" or ":raw". See perlio for a complete list of layers.

	   Note that it's important to specify the encoding if you have non-ASCII characters in your file. And the value to be compared against
	   (the string argument to "file_contents_eq()" and the regular expression argument to "file_contents_like()", for example, must be
	   decoded to Perl's internal form. The simplest way to do so use to put

	     use utf8;

	   In your test file and write it all in "UTF-8". For example:

	     use utf8;
	     use Test::More tests => 1;
	     use Test::File::Contents;

	     file_contents_eq('utf8.txt',   'aaaaaa', { encoding => 'UTF-8' });
	     file_contents_eq('latin1.txt', 'aaaaaa', { encoding => 'UTF-8' });

       "style"
	   The style of diff to output in the diagnostics in the case of a failure in "file_contents_eq_or_diff". The possible values are:

	   Unified
	   Context
	   OldStyle
	   Table
       "context"
	   Determines the amount of context displayed in diagnostic diff output. If you need to seem more of the area surrounding different lines,
	   pass this option to determine how many more links you'd like to see.

   Test Functions
       file_contents_eq

	 file_contents_eq $file, $string, $description;
	 file_contents_eq $file, $string, { encoding => 'UTF-8' };
	 file_contents_eq $file, $string, { encoding => ':bytes' }, $description;

       Checks that the file's contents are equal to a string. Pass in a Unix-style file name and it will be converted for the local file system.
       Supported options:

       "encoding"

       The old name for this function, "file_contents_is", remains as an alias.

       file_contents_eq_or_diff

	 file_contents_eq_or_diff $file, $string, $description;
	 file_contents_eq_or_diff $file, $string, { encoding => 'UTF-8' };
	 file_contents_eq_or_diff $file, $string, { style    => 'context' }, $description;

       Like "file_contents_eq()", only in the event of failure, the diagnostics will contain a diff instead of the full contents of the file. This
       can make it easier to test the contents of very large text files, and where only a subset of the lines are different. Supported options:

       "encoding"
       "style"
       "context"

       file_contents_ne

	 file_contents_ne $file, $string, $description;
	 file_contents_ne $file, $string, { encoding => 'UTF-8' };
	 file_contents_ne $file, $string, { encoding => ':bytes' }, $description;

       Checks that the file's contents do not equal a string. Pass in a Unix-style file name and it will be converted for the local file system.
       Supported options:

       "encoding"

       The old name for this function, "file_contents_isnt", remains as an alias.

       file_contents_like

	 file_contents_like $file, qr/foo/, $description;
	 file_contents_like $file, qr/foo/, { encoding => 'UTF-8' };
	 file_contents_like $file, qr/foo/, { encoding => ':bytes' }, $description;

       Checks that the contents of a file match a regular expression. The regular expression must be passed as a regular expression object created
       by "qr//".  Supported options:

       "encoding"

       file_contents_unlike

	 file_contents_unlike $file, qr/foo/, $description;
	 file_contents_unlike $file, qr/foo/, { encoding => 'UTF-8' };
	 file_contents_unlike $file, qr/foo/, { encoding => ':bytes' }, $description;

       Checks that the contents of a file do not match a regular expression. The regular expression must be passed as a regular expression object
       created by "qr//". Supported options:

       "encoding"

       file_md5sum_is

	 file_md5sum_is $file, $md5sum, $description;
	 file_md5sum_is $file, $md5sum, { encoding => 'UTF-8' };
	 file_md5sum_is $file, $md5sum, { encoding => ':bytes' }, $description;

       Checks whether a file matches a given MD5 checksum. The checksum should be provided as a hex string, for example,
       "6df23dc03f9b54cc38a0fc1483df6e21".  Pass in a Unix-style file name and it will be converted for the local file system. Supported options:

       "encoding"
	   Probably not useful unless left unset or set to ":raw".

       The old name for this function, "file_md5sum", remains as an alias.

       files_eq

	 files_eq $file1, $file2, $description;
	 files_eq $file1, $file2, { encoding => 'UTF-8' };
	 files_eq $file1, $file2, { encoding => ':bytes' }, $description;

       Tests that the contents of two files are the same. Pass in a Unix-style file name and it will be converted for the local file system.
       Supported options:

       "encoding"

       The old name for this function, "file_contents_identical", remains as an alias.

       files_eq_or_diff

	 files_eq_or_diff $file1, $file2, $description;
	 files_eq_or_diff $file1, $file2, { encoding => 'UTF-8' };
	 files_eq_or_diff $file1, $file2, { style    => 'context' }, $description;

       Like "files_eq()", this function tests that the contents of two files are the same. Unlike "files_eq()", on failure this function outputs a
       diff of the two files in the diagnostics. Supported options:

       "encoding"
       "style"
       "context"

Authors
       o   Kirrily Robert <skud@cpan.org>

       o   David E. Wheeler <david@kineticode.com>

Support
       This module is stored in an open <GitHub repository>. Feel free to fork and contribute!

       Please file bug reports via <GitHub Issues> or by sending mail to <bug-Test-File-Contents@rt.cpan.org>.

Copyright and License
       Copyright (c) 2004-2007 Kirrily Robert. Some Rights Reserved.  Copyright (c) 2007-2011 David E. Wheeler. Some Rights Reserved.

       This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl v5.10.1							    2011-02-22						 Test::File::Contents(3pm)
All times are GMT -4. The time now is 07:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy