Sponsored Content
Top Forums Shell Programming and Scripting concatenating similar files in a directory Post 302518035 by kevintse on Thursday 28th of April 2011 01:07:59 PM
Old 04-28-2011
You may do that in the following steps:
Code:
1. head -1 File2.txt > result.tmp
2. grep 'record1' File1.txt >> result.tmp
3. awk 'NR>1' File2.txt > result.tmp
4. mv result.tmp File2.txt

Kinda cumbersome, but this is what comes to my head at the first sight of your question.
I know this can be achieved more elegantly with SED, but SED is still strange to me.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

concatenating x files into a one...

... i have 4 files to concatenate but in a certain order and i wanted to do it in a shorter one line command , if possible ! 4 files : file , file0 , file1 and file2 file1 into file2 file0 into the result file into the result thanks in advance Christian (1 Reply)
Discussion started by: Nicol
1 Replies

2. UNIX for Dummies Questions & Answers

Concatenating records from 2 files

I'm trying to concatenate records from 2 files and output it to a third file. The problem I'm running into is that it seems like the "While" command is limited to processing one file at a time. It seems like you could read a record from file1 into a variable. Then do the same for the for file2.... (4 Replies)
Discussion started by: Powcmptr
4 Replies

3. Shell Programming and Scripting

Concatenating two files

HI I need to concatenate two files which are having headers. the result file should contain only the header from first file only and the header in second file have to be skipped. file1: name age sriram 23 file2 name age prabu 25 result file should be name age sriram 23 prabu ... (6 Replies)
Discussion started by: Sriramprabu
6 Replies

4. Shell Programming and Scripting

concatenating the filenames in a directory

hi all, I have a requirement where in i have to read all the filenames based on a pattern from a directory and concatenate all these file names and write it to another file. i am using the following code to do this var1='' for filename in $_DIR/${FILE_NAME}* do if if then... (7 Replies)
Discussion started by: nvuradi
7 Replies

5. UNIX for Dummies Questions & Answers

Delete X amount of similar files in a directory

Need a Unix command to save the last 20 versions of a file in a specific directory and delete everything else. Date is irrelevant. Anyone aware of such an animal? In my test, I came up with: ls -t1 /tmp/testfile* | tail -n +20 | xargs rm I don’t quite trust the author though! (1 Reply)
Discussion started by: rwsherman
1 Replies

6. Shell Programming and Scripting

Find the similar directory

Hi I have one directory whose name i don't remember exactly only starting letter i know which is Resp. Can you please let me know the command to find the similar directory in the root. Rajesh (3 Replies)
Discussion started by: guddu_12
3 Replies

7. Shell Programming and Scripting

Concatenating contents of a file with members in a directory

Hi, I have a unix file with the below structure - CustId1 CustName1 CustPhn1 /u/home/xmldata/A000001 CustId2 CustName2 CustPhn2 /u/home/xmldata/A000002 CustId3 CustName3 CustPhn3 /u/home/xmldata/A000003 Then I have another unix directory /u/home/xmldata This directory has... (3 Replies)
Discussion started by: Simanto
3 Replies

8. Shell Programming and Scripting

To find ls of similar pattern files in a directory by passing the variable.

Hi, I have file in my $datadir as below :- SAT_1.txt SAT_2.txt BAT_UD.lst BAT_DD1.lst DUTT_1.txt DUTT_la.txt Expected result :- should get all the above file in $<Filename>_file.lst Below is my code :- for i in SAT BAT DUTT do touch a.lst cd $datadir (1 Reply)
Discussion started by: satishmallidi
1 Replies

9. Shell Programming and Scripting

Finding files in directory with similar names

So, I have a directory tree that has many files named thusly: X_REVY.PDF I need to find any files that have the same X portion (which can be nearly anything) as any another file (in any directory) but have different Y portions (which can be any number from 1-99). I then need it to return... (3 Replies)
Discussion started by: Kamezero
3 Replies

10. Shell Programming and Scripting

How to move the files older than x days with similar directory structure?

Hello, I need to move all the files inside /XYZ (has multi-depth sub directories) that are older than 14 days to/ABC directory but with retaining the SAME directory structure. for example: /XYZ/1/2/3/A/b.txt should be moved as /ABC/1/2/3/A/b.txt I know about find /XYZ -type f -mtime +14... (3 Replies)
Discussion started by: prvnrk
3 Replies
Mojo::Template(3pm)					User Contributed Perl Documentation				       Mojo::Template(3pm)

NAME
Mojo::Template - Perl-ish templates! SYNOPSIS
use Mojo::Template; my $mt = Mojo::Template->new; # Simple my $output = $mt->render(<<'EOF'); % use Time::Piece; <!DOCTYPE html> <html> <head><title>Simple</title></head> % my $now = localtime; <body>Time: <%= $now->hms %></body> </html> EOF say $output; # More advanced my $output = $mt->render(<<'EOF', 23, 'foo bar'); % my ($number, $text) = @_; %= 5 * 5 <!DOCTYPE html> <html> <head><title>More advanced</title></head> <body> test 123 foo <% my $i = $number + 2; %> % for (1 .. 23) { * some text <%= $i++ %> % } </body> </html> EOF say $output; DESCRIPTION
Mojo::Template is a minimalistic and very Perl-ish template engine, designed specifically for all those small tasks that come up during big projects. Like preprocessing a configuration file, generating text from heredocs and stuff like that. <% Perl code %> <%= Perl expression, replaced with result %> <%== Perl expression, replaced with XML escaped result %> <%# Comment, useful for debugging %> <%% Replaced with "<%", useful for generating templates %> % Perl code line, treated as "<% line =%>" %= Perl expression line, treated as "<%= line %>" %== Perl expression line, treated as "<%== line %>" %# Comment line, treated as "<%# line =%>" %% Replaced with "%", useful for generating templates Escaping behavior can be reversed with the "auto_escape" attribute, this is the default in Mojolicious ".ep" templates for example. <%= Perl expression, replaced with XML escaped result %> <%== Perl expression, replaced with result %> Mojo::ByteStream objects are always excluded from automatic escaping. <%= Mojo::ByteStream->new('<div>excluded!</div>') %> Newlines can be escaped with a backslash. This is <%= 1 + 1 %> a single line And a backslash in front of a newline can be escaped with another backslash. This will <%= 1 + 1 %> result\ in multiple\ lines Whitespace characters around tags can be trimmed with a special tag ending. <%= All whitespace characters around this expression will be trimmed =%> You can capture whole template blocks for reuse later with the "begin" and "end" keywords. <% my $block = begin %> <% my $name = shift; =%> Hello <%= $name %>. <% end %> <%= $block->('Baerbel') %> <%= $block->('Wolfgang') %> Perl lines can also be indented freely. % my $block = begin % my $name = shift; Hello <%= $name %>. % end %= $block->('Baerbel') %= $block->('Wolfgang') Mojo::Template templates work just like Perl subs (actually they get compiled to a Perl sub internally). That means you can access arguments simply via @_. % my ($foo, $bar) = @_; % my $x = shift; test 123 <%= $foo %> Templates get compiled to Perl code internally, this can make debugging a bit tricky. But Mojo::Template will return Mojo::Exception objects that stringify to error messages with context. Bareword "xx" not allowed while "strict subs" in use at template line 4. 2: </head> 3: <body> 4: % my $i = 2; xx 5: %= $i * 2 6: </body> See Mojolicious::Guides::Rendering for more. ATTRIBUTES
Mojo::Template implements the following attributes. "auto_escape" my $auto_escape = $mt->auto_escape; $mt = $mt->auto_escape(1); Activate automatic XML escaping. "append" my $code = $mt->append; $mt = $mt->append('warn "Processed template"'); Append Perl code to compiled template. "capture_end" my $capture_end = $mt->capture_end; $mt = $mt->capture_end('end'); Keyword indicating the end of a capture block, defaults to "end". <% my $block = begin %> Some data! <% end %> "capture_start" my $capture_start = $mt->capture_start; $mt = $mt->capture_start('begin'); Keyword indicating the start of a capture block, defaults to "begin". <% my $block = begin %> Some data! <% end %> "code" my $code = $mt->code; $mt = $mt->code($code); Compiled template code. "comment_mark" my $comment_mark = $mt->comment_mark; $mt = $mt->comment_mark('#'); Character indicating the start of a comment, defaults to "#". <%# This is a comment %> "encoding" my $encoding = $mt->encoding; $mt = $mt->encoding('UTF-8'); Encoding used for template files. "escape_mark" my $escape_mark = $mt->escape_mark; $mt = $mt->escape_mark('='); Character indicating the start of an escaped expression, defaults to "=". <%== $foo %> "expression_mark" my $expression_mark = $mt->expression_mark; $mt = $mt->expression_mark('='); Character indicating the start of an expression, defaults to "=". <%= $foo %> "line_start" my $line_start = $mt->line_start; $mt = $mt->line_start('%'); Character indicating the start of a code line, defaults to "%". % $foo = 23; "name" my $name = $mt->name; $mt = $mt->name('foo.mt'); Name of template currently being processed, defaults to "template". Note that this method is attribute and might change without warning! "namespace" my $namespace = $mt->namespace; $mt = $mt->namespace('main'); Namespace used to compile templates, defaults to "Mojo::Template::SandBox". "prepend" my $code = $mt->prepend; $mt = $mt->prepend('my $self = shift;'); Prepend Perl code to compiled template. "replace_mark" my $replace_mark = $mt->replace_mark; $mt = $mt->replace_mark('%'); Character used for escaping the start of a tag or line, defaults to "%". <%% my $foo = 23; %> "tag_start" my $tag_start = $mt->tag_start; $mt = $mt->tag_start('<%'); Characters indicating the start of a tag, defaults to "<%". <% $foo = 23; %> "tag_end" my $tag_end = $mt->tag_end; $mt = $mt->tag_end('%>'); Characters indicating the end of a tag, defaults to "%>". <%= $foo %> "template" my $template = $mt->template; $mt = $mt->template($template); Raw template. "tree" my $tree = $mt->tree; $mt = $mt->tree($tree); Parsed tree. "trim_mark" my $trim_mark = $mt->trim_mark; $mt = $mt->trim_mark('-'); Character activating automatic whitespace trimming, defaults to "=". <%= $foo =%> METHODS
Mojo::Template inherits all methods from Mojo::Base and implements the following new ones. "new" my $mt = Mojo::Template->new; Construct a new Mojo::Template object. "build" $mt = $mt->build; Build template. "compile" my $exception = $mt->compile; Compile template. "interpret" my $output = $mt->interpret; my $output = $mt->interpret(@args); Interpret template. # Reuse template say $mt->render('Hello <%= $_[0] %>!', 'Bender'); say $mt->interpret('Fry'); say $mt->interpret('Leela'); "parse" $mt = $mt->parse($template); Parse template. "render" my $output = $mt->render($template); my $output = $mt->render($template, @args); Render template. say $mt->render('Hello <%= $_[0] %>!', 'Bender'); "render_file" my $output = $mt->render_file('/tmp/foo.mt'); my $output = $mt->render_file('/tmp/foo.mt', @args); Render template file. "render_file_to_file" my $exception = $mt->render_file_to_file('/tmp/foo.mt', '/tmp/foo.txt'); my $exception = $mt->render_file_to_file('/tmp/foo.mt', '/tmp/foo.txt', @args); Render template file to another file. "render_to_file" my $exception = $mt->render_to_file($template, '/tmp/foo.txt'); my $exception = $mt->render_to_file($template, '/tmp/foo.txt', @args); Render template to a file. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojo::Template(3pm)
All times are GMT -4. The time now is 10:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy