Sponsored Content
Top Forums Shell Programming and Scripting Merging of files with different headers to make combined headers file Post 302341962 by summer_cherry on Friday 7th of August 2009 04:10:11 AM
Old 08-07-2009
if already know the maximum and sequence of headers, should below easy perl script help you some.

If not, may need extra efforts to make out the header hash first and then use below perl script.


Code:
my %headers=(H1=>1,H2=>2,H3=>3,H4=>4,H5=>5,H6=>6);
my @header_arr = sort {$headers{$a}<=>$headers{$b}} keys %headers;
print join "|", @header_arr;
print "\n";
my %missed;
my $max=$#header_arr;
while(<DATA>){
	chomp;
	my @tmp=split("[|]",$_);
	my %hash=%headers;
	if($.==1){
		map {delete $hash{$_}} @tmp;
		map {$tt{$_}=1} values %hash;
		next;
	}
	else{
		for(my $i=1;$i<=$max+1;$i++){
			if(exists $tt{$i}){
				print "NA|";
			}
			else{
				my $tmp=shift @tmp;
				print $tmp,"|";
			}
		}
	}
	print "\n";
}
__DATA__
H1|H3|H6
12|31|33
23|41|43

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

help:how to remove headers in output file

Hi I am running a script (which compares two directory contents) for which I am getting an output of 70 pages in which few pages are blank so I was able to delete those blank lines. But I also want to delete the headers present for each page. can any one help me by providing the code... (1 Reply)
Discussion started by: raj_thota
1 Replies

2. Shell Programming and Scripting

Remove text between headers while leaving headers intact

Hi, I'm trying to strip all lines between two headers in a file: ### BEGIN ### Text to remove, contains all kinds of characters ... Antispyware-Downloadserver.com (Germany)=http://www.antispyware-downloadserver.c om/updates/ Antispyware-Downloadserver.com #2... (3 Replies)
Discussion started by: Trones
3 Replies

3. UNIX for Dummies Questions & Answers

reading file headers

Hello, I have done much googling on this, but apparently not using the right keywords. I am assuming there is some kind of header for each file on a disk which stores information such as mod time, access time, etc. I have two questions: 1) is there a way to read this header directly,... (2 Replies)
Discussion started by: Allasso
2 Replies

4. Shell Programming and Scripting

Multiple headers in a file

Hi , I have a .txt file in which I have multiple headers, the header record starts with $ symbol...like the first column name is $Account. I have to keep the header in the first line and delete all the remaining headers which are in the file. I tried using sort adc.txt | uniq -u , but my... (7 Replies)
Discussion started by: gaur.deepti
7 Replies

5. Shell Programming and Scripting

Editing File Headers

Hey Guys, Absolute neewbie here. I am trying to see if it is possible to edit headers/meta-data of files in Mac OSX. I am basically trying to change an audio file header to read 16bit instead of 24bit. We have an issue with some of our software and it regularly exports 16bit audio files with... (3 Replies)
Discussion started by: andysuperaudiom
3 Replies

6. Shell Programming and Scripting

Faster command to remove headers for files in a directory

Good evening Im new at unix shell scripting and im planning to script a shell that removes headers for about 120 files in a directory and each file contains about 200000 lines in average. i know i will loop files to process each one and ive found in this great forum different solutions... (5 Replies)
Discussion started by: alexcol
5 Replies

7. Shell Programming and Scripting

Merging File with headers

Hi I need to merge 4 files. The issue i am facing is all the files have headers and i do not want them in the final output file. Can anybody suggest how to do it? (5 Replies)
Discussion started by: Arun Mishra
5 Replies

8. Shell Programming and Scripting

Joining two files by retaining the headers.

Hi Experts, I want to join two files(file1 ,file2) which are having tab separated values,by sorting them on key column(ID) and want to redirect the output to other file(output file) along with the headers from both the files. cat file1: ID Name phone_no 205 mno 90808 200 xyz 32003... (9 Replies)
Discussion started by: bharathbangalor
9 Replies

9. Shell Programming and Scripting

Row bind multiple csv files having different column headers

All, I guess by this time someone asked this kind of question, but sorry I am unable to find after a deep search. Here is my request I have many files out of which 2 sample files provided below. File-1 (with A,B as column headers) A,B 1,2 File-2 (with C, D as column headers) C,D 4,5 I... (7 Replies)
Discussion started by: ks_reddy
7 Replies

10. Shell Programming and Scripting

awk to compare files and validate order of headers

The below awk verifies the count and order of each text file in the directory. The script does execute and produce output, however the order of the headers are not compared to key. The portion in bold is supposed to do that. If the order of the headers in each text file is the same as key, then... (0 Replies)
Discussion started by: cmccabe
0 Replies
Mojo::Headers(3pm)					User Contributed Perl Documentation					Mojo::Headers(3pm)

NAME
Mojo::Headers - Headers SYNOPSIS
use Mojo::Headers; my $headers = Mojo::Headers->new; $headers->content_type('text/plain'); $headers->parse("Content-Type: text/html "); DESCRIPTION
Mojo::Headers is a container and parser for HTTP headers. ATTRIBUTES
Mojo::Headers implements the following attributes. "max_line_size" my $size = $headers->max_line_size; $headers = $headers->max_line_size(1024); Maximum line size in bytes, defaults to the value of the "MOJO_MAX_LINE_SIZE" environment variable or 10240. METHODS
Mojo::Headers inherits all methods from Mojo::Base and implements the following new ones. "accept" my $accept = $headers->accept; $headers = $headers->accept('application/json'); Shortcut for the "Accept" header. "accept_language" my $accept_language = $headers->accept_language; $headers = $headers->accept_language('de, en'); Shortcut for the "Accept-Language" header. "accept_ranges" my $ranges = $headers->accept_ranges; $headers = $headers->accept_ranges('bytes'); Shortcut for the "Accept-Ranges" header. "add" $headers = $headers->add('Content-Type', 'text/plain'); Add one or more header lines. "authorization" my $authorization = $headers->authorization; $headers = $headers->authorization('Basic Zm9vOmJhcg=='); Shortcut for the "Authorization" header. "cache_control" my $cache_control = $headers->cache_control; $headers = $headers->cache_control('max-age=1, no-cache'); Shortcut for the "Cache-Control" header. "clone" my $clone = $headers->clone; Clone headers. "connection" my $connection = $headers->connection; $headers = $headers->connection('close'); Shortcut for the "Connection" header. "content_disposition" my $content_disposition = $headers->content_disposition; $headers = $headers->content_disposition('foo'); Shortcut for the "Content-Disposition" header. "content_length" my $content_length = $headers->content_length; $headers = $headers->content_length(4000); Shortcut for the "Content-Length" header. "content_range" my $range = $headers->content_range; $headers = $headers->content_range('bytes 2-8/100'); Shortcut for the "Content-Range" header. "content_transfer_encoding" my $encoding = $headers->content_transfer_encoding; $headers = $headers->content_transfer_encoding('foo'); Shortcut for the "Content-Transfer-Encoding" header. "content_type" my $content_type = $headers->content_type; $headers = $headers->content_type('text/plain'); Shortcut for the "Content-Type" header. "cookie" my $cookie = $headers->cookie; $headers = $headers->cookie('f=b'); Shortcut for the "Cookie" header. "date" my $date = $headers->date; $headers = $headers->date('Sun, 17 Aug 2008 16:27:35 GMT'); Shortcut for the "Date" header. "dnt" my $dnt = $headers->dnt; $headers = $headers->dnt(1); Shortcut for the "DNT" (Do Not Track) header. "etag" my $etag = $headers->etag; $headers = $headers->etag('abc321'); Shortcut for the "ETag" header. "expect" my $expect = $headers->expect; $headers = $headers->expect('100-continue'); Shortcut for the "Expect" header. "expires" my $expires = $headers->expires; $headers = $headers->expires('Thu, 01 Dec 1994 16:00:00 GMT'); Shortcut for the "Expires" header. "from_hash" $headers = $headers->from_hash({'Content-Type' => 'text/html'}); Parse headers from a hash reference. "header" my $string = $headers->header('Content-Type'); my @lines = $headers->header('Content-Type'); $headers = $headers->header('Content-Type' => 'text/plain'); Get or replace the current header values. # Multiple headers with the same name for my $header ($headers->header('Set-Cookie')) { say 'Set-Cookie:'; # Multiple lines per header say for @$header; } "host" my $host = $headers->host; $headers = $headers->host('127.0.0.1'); Shortcut for the "Host" header. "if_modified_since" my $m = $headers->if_modified_since; $headers = $headers->if_modified_since('Sun, 17 Aug 2008 16:27:35 GMT'); Shortcut for the "If-Modified-Since" header. "is_finished" my $success = $headers->is_finished; Check if header parser is finished. "is_limit_exceeded" my $success = $headers->is_limit_exceeded; Check if a header has exceeded "max_line_size". "last_modified" my $m = $headers->last_modified; $headers = $headers->last_modified('Sun, 17 Aug 2008 16:27:35 GMT'); Shortcut for the "Last-Modified" header. "leftovers" my $leftovers = $headers->leftovers; Leftovers. "location" my $location = $headers->location; $headers = $headers->location('http://127.0.0.1/foo'); Shortcut for the "Location" header. "names" my $names = $headers->names; Generate a list of all currently defined headers. "parse" $headers = $headers->parse("Content-Type: text/foo "); Parse formatted headers. "proxy_authenticate" my $authenticate = $headers->proxy_authenticate; $headers = $headers->proxy_authenticate('Basic "realm"'); Shortcut for the "Proxy-Authenticate" header. "proxy_authorization" my $proxy_authorization = $headers->proxy_authorization; $headers = $headers->proxy_authorization('Basic Zm9vOmJhcg=='); Shortcut for the "Proxy-Authorization" header. "range" my $range = $headers->range; $headers = $headers->range('bytes=2-8'); Shortcut for the "Range" header. "referrer" my $referrer = $headers->referrer; $headers = $headers->referrer('http://mojolicio.us'); Shortcut for the "Referer" header, there was a typo in RFC 2068 which resulted in "Referer" becoming an official header. "remove" $headers = $headers->remove('Content-Type'); Remove a header. "sec_websocket_accept" my $accept = $headers->sec_websocket_accept; $headers = $headers->sec_websocket_accept('s3pPLMBiTxaQ9kYGzzhZRbK+xOo='); Shortcut for the "Sec-WebSocket-Accept" header. "sec_websocket_key" my $key = $headers->sec_websocket_key; $headers = $headers->sec_websocket_key('dGhlIHNhbXBsZSBub25jZQ=='); Shortcut for the "Sec-WebSocket-Key" header. "sec_websocket_origin" my $origin = $headers->sec_websocket_origin; $headers = $headers->sec_websocket_origin('http://example.com'); Shortcut for the "Sec-WebSocket-Origin" header. "sec_websocket_protocol" my $protocol = $headers->sec_websocket_protocol; $headers = $headers->sec_websocket_protocol('sample'); Shortcut for the "Sec-WebSocket-Protocol" header. "sec_websocket_version" my $version = $headers->sec_websocket_version; $headers = $headers->sec_websocket_version(13); Shortcut for the "Sec-WebSocket-Version" header. "server" my $server = $headers->server; $headers = $headers->server('Mojo'); Shortcut for the "Server" header. "set_cookie" my $set_cookie = $headers->set_cookie; $headers = $headers->set_cookie('f=b; path=/'); Shortcut for the "Set-Cookie" header. "status" my $status = $headers->status; $headers = $headers->status('200 OK'); Shortcut for the "Status" header. "to_hash" my $single = $headers->to_hash; my $multi = $headers->to_hash(1); Turn headers into hash reference, nested array references to represent multi line values are disabled by default. "to_string" my $string = $headers->to_string; Turn headers into a string, suitable for HTTP 1.1 messages. "trailer" my $trailer = $headers->trailer; $headers = $headers->trailer('X-Foo'); Shortcut for the "Trailer" header. "transfer_encoding" my $transfer_encoding = $headers->transfer_encoding; $headers = $headers->transfer_encoding('chunked'); Shortcut for the "Transfer-Encoding" header. "upgrade" my $upgrade = $headers->upgrade; $headers = $headers->upgrade('websocket'); Shortcut for the "Upgrade" header. "user_agent" my $user_agent = $headers->user_agent; $headers = $headers->user_agent('Mojo/1.0'); Shortcut for the "User-Agent" header. "www_authenticate" my $authenticate = $headers->www_authenticate; $headers = $headers->www_authenticate('Basic realm="realm"'); Shortcut for the "WWW-Authenticate" header. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojo::Headers(3pm)
All times are GMT -4. The time now is 06:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy