Sponsored Content
Top Forums Shell Programming and Scripting use of format file to extract columns from a source file Post 302268266 by ivhb on Monday 15th of December 2008 09:43:00 AM
Old 12-15-2008
Code:
awk -F "(,|[ \t]+)" '
NR == FNR {
  if (cnt[$1] ++ == 0)
     col[j++] = $1
}
NR != FNR {
  for (i = 0; i < j; i ++)
     printf ("%s%s", i ? " " : "", $(col[i]))
  printf ("\n")
}' your-format-file  your-data-file

output:
d f g
5 9 7
1 4 5
1 4 5

is this what you want?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract and format information from a file

Hi, Following is sample portion of the file; <JDBCConnectionPool DriverName="oracle.jdbc.OracleDriver" MaxCapacity="10" Name="MyApp_DevPool" PasswordEncrypted="{3DES}7tXFH69Xg1c=" Properties="user=MYAPP_ADMIN" ShrinkingEnabled="false" ... (12 Replies)
Discussion started by: sujoy101
12 Replies

2. Shell Programming and Scripting

Help, need to extract columns from file

I have huge fixed width, text file in unix box and I need to extract columns found between the width 105 and 200 and output it to a new file. Can anyone tell me how to extract it? Thanks for your help. (1 Reply)
Discussion started by: kiran2k
1 Replies

3. UNIX for Advanced & Expert Users

How to extract a particular file in tar.Z format

Hi , I need to extarct only a particulay files from the tar.Z. ie i need to extract one.txt from test.tar.Z. The test.tar.Z may contain lot of file and folders. Please help me to extract particular file to some location. Regards, Kalai. (1 Reply)
Discussion started by: kalpeer
1 Replies

4. Shell Programming and Scripting

Extract Columns from file

Hi All, Could you please help me with following: I have to parse a .csv file. For example: If the csv file contains 3 columns, then i have to print the column names. The field separator is (comma). example.csv (contains 2 lines as follows) This is,a test file, for validation... (2 Replies)
Discussion started by: vfrg
2 Replies

5. Shell Programming and Scripting

fileutility to extract columns from source file

Hi experts,Please help me for the below requirement.i have a source file.(lets say contains 50 columns). I am extarcting five columns from the source file by using pattern file.for exampleinput file:--------a,b,c,d,"a,g","v b",s,koutputfile=======a,"a,g","v b",s,kThanks in advancesubhendu (1 Reply)
Discussion started by: subhendu81
1 Replies

6. Shell Programming and Scripting

extracting columns using pattern file from source file

Hi experts,Please help me for the below requirement. i have a source file.(lets say contains 50 columns). I am extarcting five columns from the source file by using pattern file. for example input file:--------a,b,c,d,"a,g","v b",s,koutputfile=======a,"a,g","v b",s,kThanks in advance subhendu (2 Replies)
Discussion started by: subhendu81
2 Replies

7. Shell Programming and Scripting

How to Split a source file in specified format?

Requirement: Need to split a source file say a1.txt which can be of size upto 150 MB into 25 target files each with a max size of 25 MB along with the header line in each target file. NOTE: Few target files can be empty also ,but 25 files must be generated for 1 source file( I can expect upto... (4 Replies)
Discussion started by: mad_man12
4 Replies

8. Shell Programming and Scripting

Extract the correct format of file Name

All, Objective : Extract the correct format of a file name. Please share the script command which will extract the correct format of the file after untarring. Example : If the file is of .csv format then extract filename.csv if the file is having .CSV then extract the same.CSV if the file... (1 Reply)
Discussion started by: Mahesh G
1 Replies

9. Shell Programming and Scripting

Extract columns into seperate file

I have a comma delimited file as per the one below and I am currently extracting the values in 2 columns (COL1 & COL6) to produce a smaller trimmed down version of the file which only contains the columns we need; COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8,COL9... (1 Reply)
Discussion started by: Ads89
1 Replies

10. Shell Programming and Scripting

Match Columns in one file and extract columns from another file

Kindly help merging information from two files with the following data structure. I want to match for the CHR-SNP in Foo and get the columns that match from CHROM-rsID Fields 1 & 2 of foo may have duplicates, however, a joint key of Fields $1$2$3$4 is unique. Also would be helpful to clean up... (4 Replies)
Discussion started by: genehunter
4 Replies
Term::Cap(3pm)						 Perl Programmers Reference Guide					    Term::Cap(3pm)

NAME
Term::Cap - Perl termcap interface SYNOPSIS
require Term::Cap; $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed }; $terminal->Trequire(qw/ce ku kd/); $terminal->Tgoto('cm', $col, $row, $FH); $terminal->Tputs('dl', $count, $FH); $terminal->Tpad($string, $count, $FH); DESCRIPTION
These are low-level functions to extract and use capabilities from a terminal capability (termcap) database. More information on the terminal capabilities will be found in the termcap manpage on most Unix-like systems. METHODS The output strings for Tputs are cached for counts of 1 for performance. Tgoto and Tpad do not cache. "$self->{_xx}" is the raw termcap data and "$self->{xx}" is the cached version. print $terminal->Tpad($self->{_xx}, 1); Tgoto, Tputs, and Tpad return the string and will also output the string to $FH if specified. Tgetent Returns a blessed object reference which the user can then use to send the control strings to the terminal using Tputs and Tgoto. The function extracts the entry of the specified terminal type TERM (defaults to the environment variable TERM) from the database. It will look in the environment for a TERMCAP variable. If found, and the value does not begin with a slash, and the terminal type name is the same as the environment string TERM, the TERMCAP string is used instead of reading a termcap file. If it does begin with a slash, the string is used as a path name of the termcap file to search. If TERMCAP does not begin with a slash and name is different from TERM, Tgetent searches the files $HOME/.termcap, /etc/termcap, and /usr/share/misc/termcap, in that order, unless the environment variable TERMPATH exists, in which case it specifies a list of file pathnames (separated by spaces or colons) to be searched instead. Whenever multiple files are searched and a tc field occurs in the requested entry, the entry it names must be found in the same file or one of the succeeding files. If there is a ":tc=...:" in the TERMCAP environment variable string it will continue the search in the files as above. The extracted termcap entry is available in the object as "$self->{TERMCAP}". It takes a hash reference as an argument with two optional keys: OSPEED The terminal output bit rate (often mistakenly called the baud rate) for this terminal - if not set a warning will be generated and it will be defaulted to 9600. OSPEED can be be specified as either a POSIX termios/SYSV termio speeds (where 9600 equals 9600) or an old DSD-style speed ( where 13 equals 9600). TERM The terminal type whose termcap entry will be used - if not supplied it will default to $ENV{TERM}: if that is not set then Tgetent will croak. It calls "croak" on failure. Tpad Outputs a literal string with appropriate padding for the current terminal. It takes three arguments: $string The literal string to be output. If it starts with a number and an optional '*' then the padding will be increased by an amount relative to this number, if the '*' is present then this amount will me multiplied by $cnt. This part of $string is removed before output/ $cnt Will be used to modify the padding applied to string as described above. $FH An optional filehandle (or IO::Handle ) that output will be printed to. The padded $string is returned. Tputs Output the string for the given capability padded as appropriate without any parameter substitution. It takes three arguments: $cap The capability whose string is to be output. $cnt A count passed to Tpad to modify the padding applied to the output string. If $cnt is zero or one then the resulting string will be cached. $FH An optional filehandle (or IO::Handle ) that output will be printed to. The appropriate string for the capability will be returned. Tgoto Tgoto decodes a cursor addressing string with the given parameters. There are four arguments: $cap The name of the capability to be output. $col The first value to be substituted in the output string ( usually the column in a cursor addressing capability ) $row The second value to be substituted in the output string (usually the row in cursor addressing capabilities) $FH An optional filehandle (or IO::Handle ) to which the output string will be printed. Substitutions are made with $col and $row in the output string with the following sprintf() line formats: %% output `%' %d output value as in printf %d %2 output value as in printf %2d %3 output value as in printf %3d %. output value as in printf %c %+x add x to value, then do %. %>xy if value > x then add y, no output %r reverse order of two parameters, no output %i increment by one, no output %B BCD (16*(value/10)) + (value%10), no output %n exclusive-or all parameters with 0140 (Datamedia 2500) %D Reverse coding (value - 2*(value%16)), no output (Delta Data) The output string will be returned. Trequire Takes a list of capabilities as an argument and will croak if one is not found. EXAMPLES
use Term::Cap; # Get terminal output speed require POSIX; my $termios = new POSIX::Termios; $termios->getattr; my $ospeed = $termios->getospeed; # Old-style ioctl code to get ospeed: # require 'ioctl.pl'; # ioctl(TTY,$TIOCGETP,$sgtty); # ($ispeed,$ospeed) = unpack('cc',$sgtty); # allocate and initialize a terminal structure $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed }; # require certain capabilities to be available $terminal->Trequire(qw/ce ku kd/); # Output Routines, if $FH is undefined these just return the string # Tgoto does the % expansion stuff with the given args $terminal->Tgoto('cm', $col, $row, $FH); # Tputs doesn't do any % expansion. $terminal->Tputs('dl', $count = 1, $FH); COPYRIGHT AND LICENSE
Please see the README file in distribution. AUTHOR
This module is part of the core Perl distribution and is also maintained for CPAN by Jonathan Stowe <jns@gellyfish.com>. SEE ALSO
termcap(5) perl v5.16.2 2012-10-11 Term::Cap(3pm)
All times are GMT -4. The time now is 10:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy