Sponsored Content
Top Forums Shell Programming and Scripting Moving lines within a txt file Post 302137843 by innocentspirit on Thursday 27th of September 2007 06:53:34 AM
Old 09-27-2007
Moving lines within a txt file

A newbie to shell scripting.....

I need some assistance in doing the following:

I have a system generated text file(a makefile basically).

Before I can execute the make command, I need to modify one section of this generated file.

The generated section is as follows:

# INCLUDE macro for SCI
#~~~~~~~~~~~~~~~~~~~~~~~
XYZ_MAIN_INCLUDE = \
-I/Path_1 \
-I/Path_2 \
-I/Path_3 \
-I/Path_4

Basically, Path_4 has be placed at the start of the INCLUDE section with appropriate changes to new line delimiters.

This modified section should look as follows:

# INCLUDE macro for SCI
#~~~~~~~~~~~~~~~~~~~~~~~
XYZ_MAIN_INCLUDE = \
-I/Path_4 \
-I/Path_1 \
-I/Path_2 \
-I/Path_3

I have to make similar changes to 6 different files in 6 different locations in the directory structure before I can execute make.

Can I achieve this using a shell script without having to modify all the files manually everytime I need to execute a make?

Thanks in advance for any suggestions.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how do I filter double lines from a txt file

Hi, I have a file with the following: access-list.txt router1 access-list 1 permit any any access-list 1 deny any any router2 access-list 2 permit any any access-list 2 deny any any router3 access-list 3 permit any any access-list 3 deny any any I want to hava an output that... (10 Replies)
Discussion started by: I-1
10 Replies

2. Shell Programming and Scripting

print all even lines of a txt file

In other news, I have a colors text file with hundreds of lines, and I want to print only the even numbered lines. for example I have this file looks something like this: ALLCOLORS.TXT red red green red blue red red red green red red blue green green green blue blue blue red blue blue blue... (1 Reply)
Discussion started by: ajp7701
1 Replies

3. Shell Programming and Scripting

Urgent Need Help! Merging lines in .txt file

I need to write a script that reads through an input .txt file and replaces the end value with the end value of the next line for lines that have distance <=4000. The first label line is not actually in the input. In the below example, 3217 is the distance from the end of the first line to the... (12 Replies)
Discussion started by: awknerd
12 Replies

4. Shell Programming and Scripting

Deleting lines that contain spaces in a txt file

I need some help deleting lines in a file that contain spaces. Im sure awk or sed will work but i dont know much about those commands. Any help is appreciated :D (7 Replies)
Discussion started by: r04dw4rri0r
7 Replies

5. Shell Programming and Scripting

sed to cp lines x->y from 1.txt into lines a->b in file2.txt

I have one base file, and multiple target files-- each have uniform line structure so no need to use grep to find things-- can just define sections by line number. My question is quite simple-- can I use sed to copy a defined block of lines (say lines 5-10) from filename1.txt to overwrite an... (3 Replies)
Discussion started by: czar21
3 Replies

6. Shell Programming and Scripting

merging two .txt files by alternating x lines from file 1 and y lines from file2

Hi everyone, I have two files (A and B) and want to combine them to one by always taking 10 rows from file A and subsequently 6 lines from file B. This process shall be repeated 40 times (file A = 400 lines; file B = 240 lines). Does anybody have an idea how to do that using perl, awk or sed?... (6 Replies)
Discussion started by: ink_LE
6 Replies

7. UNIX for Dummies Questions & Answers

find lines in file1.txt not found in file2.txt memory problem

I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory) diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//' Is there a better more efficient way to find the lines in one file... (5 Replies)
Discussion started by: raptor25
5 Replies

8. Shell Programming and Scripting

Random shuffle of lines of a TXT file

Hello friends, I have a TXT file with 300 lines in it. I need to shuffle all the lines (randomly) so that they get into different order. Can anyone pls provide easy way, if any? I got it done by doing this below but I see it very lengthy/inefficient way. call random function to generate... (2 Replies)
Discussion started by: prvnrk
2 Replies

9. Shell Programming and Scripting

Getting lines from .txt file

Hi I have a file with contents: NAMES John carrey williams How can I get all the names and store them in seperate variables(or arrays) please keep in mind that the no. of such names is not known.Three here is a bogus value ~thanks (4 Replies)
Discussion started by: leghorn
4 Replies

10. UNIX for Dummies Questions & Answers

Moving lines of file to command line

I have a file in which each line is the name of another file. Is there a way to serve them to the command line? For example, if the file contains file1.txt file2.txt file3.txt ... file9.txt is there a way to insert them in the command as a batch? If I ran a command like grep... (4 Replies)
Discussion started by: wbport
4 Replies
Template::FAQ(3pm)					User Contributed Perl Documentation					Template::FAQ(3pm)

NAME
Template::FAQ - Frequently Asked Questions about the Template Toolkit Template Toolkit Language Why doesn't [% a = b IF c %] work as expected? There's a limitation in the TT2 parser which means that the following code doesn't work as you might expect: [% a = b IF c %] The parser interprets it as an attempt to set "a" to the result of "b IF c", like this: [% a = (b IF c) %] If you want to set "a = b" only if "c" is true, then do this instead: [% SET a = b IF c %] The explicit "SET" keyword gives the parser the clue it needs to do the right thing. NOTE: this will be fixed in TT3 If I'm using TT to write out a TT template, is there a good way to escape [% and %]? You can do something like this: [% stag = "[\%" etag = "%]" %] and then: [% stag; 'hello'; etag %] Or you can use the "TAGS" directive, like so: [% TAGS [- -] %] [- INCLUDE foo -] # is a directive [% INCLUDE foo %] # not a directive How do I iterate over a hash? This is covered in the Template::Manual::VMethods section of the manual. A list of all the keys that are in the hash can be obtained with the "keys" virtual method. You can then iterate over that list and by looking up each key in turn get the value. [% FOREACH key = product.keys %] [% key %] => [% product.$key %] [% END %] Plugins How do I get the Table plugin to order data across rather than down? Order the data into rows: Steve Karen Jeff Brooklyn Nantucket Fairfax NY MA VA [% USE table(data, rows=3) %] Then ask for each column [% FOREACH column = table.cols %] And then print each item in the column going across the output rows [% FOREACH item = column %] <td>[% item %]</td> [% END %] Accessing Cookies Jeff Boes <jboes@nexcerpt.com> asks: Does anyone have a quick-n-dirty approach to accessing cookies from templates? Jonas Liljegren answers: [% USE CGI %] <p>The value is [% CGI.cookie('cookie_name') | html %] Extending the Template Toolkit Can I serve templates from a database? Short answer: yes, Chris Nandor has done this for Slash. You need to subclass Template::Provider. See the mailing list archives for further info. Can I fetch templates via http? To do the job properly, you should subclass Template::Provider to "Template::Provider::HTTP" and use a "PREFIX_MAP" option to bind the "http" template prefix to that particular provider (you may want to go digging around in the Changes file around version 2.01 for more info on "PREFIX_MAP" - it may not be properly documented anywhere else...yet!). e.g. use Template::Provider::HTTP; my $file = Template::Provider( INCLUDE_PATH => [...] ); my $http = Template::Provider::HTTP->new(...); my $tt2 = Template->new({ LOAD_TEMPLATES => [ $file, $http ], PREFIX_MAP => { file => '0', # file:foo.html http => '1', # http:foo.html default => '0', # foo.html => file:foo.html } }); Now a template specified as: [% INCLUDE foo %] will be served by the 'file' provider (the default). Otherwise you can explicitly add a prefix: [% INCLUDE file:foo.html %] [% INCLUDE http:foo.html %] [% INCLUDE http://www.xyz.com/tt2/header.tt2 %] This same principal can be used to create a DBI template provider. e.g. [% INCLUDE dbi:foo.html %] Alas, we don't yet have a DBI provider as part of the Template Toolkit. There has been some talk on the mailing list about efforts to develop DBI and/or HTTP providers but as yet no-one has stepped forward to take up the challenge... In the mean time, Craig Barrat's post from the mailing list has some useful pointers on how to achieve this using existing modules. See http://tt2.org/pipermail/templates/2001-May/000954.html <http://tt2.org/pipermail/templates/2001-May/000954.html> Miscellaneous How can I find out the name of the main template being processed? The "template" variable contains a reference to the Template::Document object for the main template you're processing (i.e. the one provided as the first argument to the Template process() method). The "name" method returns its name. [% template.name %] # e.g. index.html How can I find out the name of the current template being processed? The "template" variable always references the main template being processed. So even if you call [% INCLUDE header %], and that calls [% INCLUDE menu %], the "template" variable will be unchanged. index.html: [% template.name %] # index.html [% INCLUDE header %] header: [% template.name %] # index.html [% INCLUDE menu %] menu: [% template.name %] # index.html In constrast, the "component" variable always references the current template being processed. index.html [% component.name %] # index.html [% INCLUDE header %] header: [% component.name %] # header [% INCLUDE menu %] menu: [% component.name %] # menu How do I print the modification time of the template or component? The "template" and "component" variables reference the main template and the current template being processed (see previous questions). The "modtime" method returns the modification time of the corresponding template file as a number of seconds since the Unix epoch (00:00:00 GMT 1st January 1970). This number doesn't mean much to anyone (except perhaps serious Unix geeks) so you'll probably want to use the Date plugin to format it for human consumption. [% USE Date %] [% template.name %] last modified [% Date.format(template.modtime) %] How can I configure variables on a per-request basis? One easy way to achieve this is to define a single "PRE_PROCESS" template which loads in other configuration files based on variables defined or other conditions. For example, my setup usually looks something like this: PRE_PROCESS => 'config/main' config/main: [% DEFAULT style = 'text' section = template.section or 'home'; PROCESS config/site + config/urls + config/macros + "config/style/$style" + "config/section/$section" + ... %] This allows me to set a single 'style' variable to control which config file gets pre-processed to set my various style options (colours, img paths, etc). For example: config/style/basic: [% style = { name = style # save existing 'style' var as 'style.name' # define various other style variables.... col = { back => '#ffffff' text => '#000000' # ...etc... } logo = { # ...etc... } # ...etc... } %] Each source template can declare which section it's in via a META directive: [% META title = 'General Information' section = 'info' %] ... This controls which section configuration file gets loaded to set various other variables for defining the section title, menu, etc. config/section/info: [% section = { name = section # save 'section' var as 'section.name' title = 'Information' menu = [ ... ] # ...etc... } %] This illustrates the basic principal but you can extend it to perform pretty much any kind of per-document initialisation that you require. Why do I get rubbish for my utf-8 templates? First of all, make sure that your template files define a Byte Order Mark <http://en.wikipedia.org/wiki/Byte_Order_Mark> If you for some reason don't want to add BOM to your templates, you can force Template to use a particular encoding (e.g. "utf8") for your templates with the "ENCODING" option. my $template = Template->new({ ENCODING => 'utf8' }); Questions About This FAQ Why is this FAQ so short? Because we don't have anyone maintaining it. Can I help? Yes please :-) perl v5.14.2 2011-12-20 Template::FAQ(3pm)
All times are GMT -4. The time now is 04:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy