Sponsored Content
Top Forums Shell Programming and Scripting Extract columns from a file if the name dont exist put blank Post 302459770 by nightrider on Tuesday 5th of October 2010 10:30:51 AM
Old 10-05-2010
Hi Tyler,
Appreciate your prompt reply.
What if I don't know beforehand the columns that were missing? Will your code still work?

I was using for loop in my earlier posting to perform a column header name matching to try to find out 1) the missing column ( as this is not fixed)
2) the position of the column if it matches

I thought this is the way to go? U think u can help me?
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Tab Completion showing files that Dont Exist

Has anyone seen this before? if i ls a particular directory (an email Maildir) i get a long list of files, if i 'du -h' that same directory, i get messages like: du: `./1053894791.17207_0.srweb,S=6199': No such file or directory strange. so using tab will complete this filename too, giving... (3 Replies)
Discussion started by: dittonamed
3 Replies

2. Shell Programming and Scripting

How to extract visually blank lines form the file

Hi, Could some one help me to get rid of visually blank lines from a file using shell or awk or sed (on Solaris machine)? When I use grep grep -v ^$ inputfile >outputfile it removes some blank lines.. but it seems some tab plus space balnk lines remains. thaen I used "grep -v '^]*$' ... (1 Reply)
Discussion started by: hadsuresh
1 Replies

3. Shell Programming and Scripting

Removing blank columns from a file

Hi, I have a sample file as shown below -- id parent name dba -----------------------------------... (7 Replies)
Discussion started by: sumirmehta
7 Replies

4. Shell Programming and Scripting

ls | grep (i dont know what to put here)

Dear users, I googled for a while, but i have got a lot of different answers regarding a simple unix command. lets say there are a lot of files in a directory. How can i list the files in a directory whose file types is "text"? Thank you in advance (4 Replies)
Discussion started by: kevincobain2000
4 Replies

5. UNIX for Dummies Questions & Answers

Rsync copy files if dont exist

I have a setup where I have two drives. TV TVbackup For what ever reason, I have a lot of content on my TVbackup drive which isn't on my TV drive. I want to copy all the files across which are on TVbackup but are not currently on TV. If there is a file with the same name but a... (2 Replies)
Discussion started by: Spadez
2 Replies

6. Shell Programming and Scripting

How to sort a text file if certain columns are blank?

Dear all, I am trying to sort a text file based on column 3, 10, 11 and 12. But certain column are blank for some lines. Column 3 has to be in ascending order after sorting. Part of my input file is as follows: CN727990 1 A01 4703 5083 73.28 - A_scaffold000011 4365605 4365985 73.28 +... (10 Replies)
Discussion started by: huiyee1
10 Replies

7. Shell Programming and Scripting

Inserting blank columns in already present CSV file

Hi, i have a csv file which have headers and values of it like below : headers --> CI Ref SerialNumber LastScanDate values --> VMware-42,VMware-42,Tue, 20 May 2014 11:03:44 +0000 i want to have a above csv in below format : headers --> CI Name CI Description CI Ref... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

8. Shell Programming and Scripting

Remove blank columns from a tab delimited text file

Hello, I have some tab delimited files that may contain blank columns. I would like to delete the blank columns if they exist. There is no clear pattern for when a blank occurs. I was thinking of using sed to replace instances of double tab with blank, sed 's/\t\t//g' All of the examples... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

9. Shell Programming and Scripting

Script to find blank records in a file except for few columns

I have a file with the following format: X|High|2|GIC|DM||XHM|||6 Months X|Moderate|2|GIC|DM||XHM|||6 Months X|High|2|GCM|DM||XSF|||6 Months X|Med|2|GCM|DM||XSF|||6 Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th... (10 Replies)
Discussion started by: chatwithsaurav
10 Replies

10. Shell Programming and Scripting

Extract data from a log file and put it in a file

Hi, I would like to seek your help for a script that will extract data from log file and put it in a file. Sample log file 2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_TH account: 123456789 aiSessionNumber: 660640464 mapName: xxx to yyy errorDesc: Translation Error:ErrorNumber : 993 ... (2 Replies)
Discussion started by: neverwinter112
2 Replies
SLICE(1)                                                        Ralf S. Engelschall                                                       SLICE(1)

NAME
Slice -- Extract pre-defined slices from an ASCII file SYNOPSIS
slice [-v] [-y outputpolicy] [-o sliceterm:outputfile[@chmodcmd][#outputpolicy] ..] [inputfile] slice [-V] [-h] VERSION
1.3.8 (10-Feb-2002) DESCRIPTION
Input Principle The slice program reads inputfile (or from STDIN if inputfile is not given or equal ``"-"'') and divides its already prepared ASCII contents into possibly overlapping areas, called slices. These slices are determined by enclosing blocks defined by begin and end delimiters which have to be already in the file. These block delimiters use the syntax [NAME: ... :NAME] or alternatively (if there is no misinterpretation possible, i.e. no overlapping or stacked slices) [NAME: ... :] The NAME identifier has to match against the regular expression ``"[_A-Z0-9]+"'', i.e. NAME is a string consisting only of uppercase letters, digits or underscore characters. There can be as many such slice definitions as you like and there can be more than one slice with the same name. The resulting slice is the union of all equal named slices. Actually use this to spread a big slice over disjunct peaces of inputfile. Output Selection Scheme The final output data gets calculated by a slice term consisting of slice names and set theory operators. The following syntax is recognized (in order of LR(1) grammar parsing) for slice terms: SLICE_TERM ::= "NAME" The slice NAME itself. This name has to match against the regex ``"[_A-Z0-9*{}]+"''. Here two cases are possible: "NAME" is either a plain slice name consisting only of uppercase letters, digits or an underscore character. Or it is a wildcarded slice name indicated by an asterisk character. The first variant just expands to the union of all slices named exactly "NAME". The second variant expands to the union of all slices which match against the wildcard pattern "NAME". Here the asterisk has the semantical meaning of none or any number of characters. There is one special case, when the asterisk is immediately followed by characters enclosed within braces, it means none or any number of characters, but not this sequence of characters. SLICE_TERM ::= "!NAME" | "~NAME" The complement of slice NAME (i.e. ALLNAME). In formula: {x in ALL: x not in NAME} SLICE_TERM ::= "NAME1xNAME2", "NAME1^NAME2" The exclusive-or relation between slice NAME1 and slice NAME2. In set theory also called symmetric difference: (NAME1uNAME2)(NAME1nNAME2) or alternatively (NAME1n!NAME2)u(!NAME1nNAME2). In formula: {x in ALL: (x in NAME1 or x in NAME2) and not (x in NAME1 and x in NAME2)}. SLICE_TERM ::= "NAME1NAME2", "NAME1-NAME2" The difference of slice NAME1 and slice NAME2, i.e. NAME1 minus NAME2. In formula: {x in ALL: x in NAME1 and x not in NAME2} SLICE_TERM ::= "NAME1nNAME2" | "NAME1%NAME2" The intersection of slice NAME1 and slice NAME2. In formula: {x in ALL: x in NAME1 and x in NAME2} SLICE_TERM ::= "NAME1uNAME2", "NAME1+NAME2" The union of slice NAME1 and slice NAME2. In formula: {x in ALL: x in NAME1 or x in NAME2} SLICE_TERM ::= "(" SLICE_TERM ")" A grouped slice term. Use this to force a different order of evaluation. By default, all operators are left-associative, except complement which is right-associative. Operators are listed below from lowest to highest precedence: - u x n ! Advanced Selection: Slice Levels Because slices can be overlapping and stacked, a definition level is assigned to each slice while the input is parsed. These levels range from 1 to the maximum encountered (the level 0 is the whole file, i.e. "ALL"). When a slice begins, it is assigned the lowest free level, beginning with level 1. As long as one level is in use, it cannot be assigned again until the end delimiter of the corresponding slice is seen. An example: [A:[B::B]:A][C:[D:[E::C]:D][F::E]:F] 3 E-----------E 2 B--B D--------D 1 A--------A C--------C F-----F 0 Here slice A is assigned level 1. Then B is assigned level 2 because level 1 is still in use by A. Then the end of B is reached, level 2 is freed. Then the end of A is reached and level 1 is also free now, so C is assigned level 1 again. Now only level 1 is in use, so D is assigned level 2. Then E is assigned level 3. Then the end of C is seen and level 1 freed. Then the end of D is seen and level 2 is freed. Now F begins and because only level 3 is in use, it gets level 1 assigned. Then the end of E frees level 3 and the end of F frees level 1. Finally no levels are still in use. This indicates that the slicing is correct. If there are any used levels left at the end of this process this indicates an input error and slice responds with an error message displaying the still open slices. This complicated level mechanism is needed for granular set operations where particular slices should be included or excluded only. So, to make life easier, a few pseudo-slices are automatically defined: "DEFn" The union of all user-defined slices at exactly level n (0 <= n <= oo). "UNDEFn" The union of all non-user-defined slices at exactly level n (0 <= n <= oo). This actually is just "!DEFn". "DEF" The union of all user-defined slices at all levels, beginning at level 1. This actually is the union of all "DEFn" slices. "UNDEF" The union of all non-user-defined slices at all levels, beginning with 1. This actually is just "!DEF". "ALL" The whole file. This actually is just "UNDEF0", because at level 0 there are no user defined slices, so all is undefined. NAME"@" This is the slice NAME minus the union of all "DEFn" slices with min(NAME) <= n <= oo. Here min(NAME) is the lowest level plus one where NAME ever occurred. You can read this as ``NAME without all other slices at higher levels which overwrite it''. This sounds a little bit crazy, but actually is the most important construct. Try to understand it or your slice terms become very complicated. OPTIONS
[-y outputpolicy] This flag changes output policy depending on events: "u" when an undefined set is encountered, "w" for an unmatched wildcard set, "z" when output is empty and "s" if it only consists of whitespace characters. Each letter is followed by a digit telling which action is bound to such events: 0 to ignore such events, 1 to display a warning message and continue, 2 to skip concerned file and continue, and 3 to abort with an error message. This flag consists of one or more events specifications, and default is "u0w0s0z0". [-o sliceterm:outputfile[@chmodcmd][#outputpolicy] ..] This redirects the output to a file. Usually the whole file will be send to "STDOUT" (same as "ALL:-"). You can use this option more than once to output to more than one file while the corresponding sliceterm determines which output data will be included into each output file. The optional chmodcmd string is intended for specifying options for the chmod command, which is applied to outputfile after writing. For instance use ``"a+r"'' to make sure the file is readable by a webserver of ``"u+x"'' to create a file with the execution bit set (usually used for SSI files on a webserver with the "XBitHack" option available). The optional outputpolicy string allows changing output policy for only this output file without changing its global meaning. See above for information on output policy. Be careful here: When you use parenthesis or asterisks inside sliceterm you have to make sure it is really passed to slice this way, i.e. usually you have to escape these characters from interpolation by the used shell. Do this either by adding backslashes in front of these characters or just surround the complete option argument with single quotes (''). -v This sets verbose mode where some processing information will be given on the console for debugging purpose. -V Displays the version identification string. -h Displays the usage page. SPECIAL FEATURE
Sometimes it can be very useful to be able to provide command line options directly within the input file, for instance to setup one or more -o options. For this slice recognizes lines of the form %!slice OPTIONS in the input file and automatically adds OPTIONS to the argument line options. These lines have to start in column 0. Example: %!slice -oTOC:contents.txt EXAMPLE
Assume the following simple multi-language article file article.src, written in HTML: <html> <head> <title>[EN:Titlepage:][DE:Titelseite:]</title> </head> <body> <center> <h1>[EN:The Title itself:][DE:Der Titel selbst:]</h1> </center> <blockquote> [EN:...English Abstract...:] [DE:...Deutsche Zusammenfassung...:] </blockquote> [EN:...English Text...:] [DE:...Deutscher Text...:] </body> </html> The command slice -o ENuUNDEF:article.html.en -o DEuUNDEF:article.html.de then creates the following to files: article.html.en: <html> <head> <title>Titlepage</title> </head> <body> <center> <h1>The Title itself</h1> </center> <blockquote> ...English Abstract... </blockquote> ...English Text... </body> </html> article.html.de: <html> <head> <title>Titelseite</title> </head> <body> <center> <h1>Der Titel selbst</h1> </center> <blockquote> ...Deutsche Zusammenfassung... </blockquote> ...Deutscher Text... </body> </html> RESTRICTION
The current implementation only handles anonymous end delimiters ``":]"'' correct in clear cases where no mis-interpretation is possible, i.e. when no overlapping occurs. For instance in ...[A:...[B:...:A]...:]... the end delimiter is not correctly assign to the `B' slice. So, be careful when using anonymous end delimiters in overlapping situations. Pure stacking like ...[A:...[B:...:]...:]... is allowed and handled correctly, but only when you interpret this as ...[A:...[B:...:B]...:A]... COPYRIGHT
Copyright (c) 1997-2002 Ralf S. Engelschall. Copyright (c) 1999-2002 Denis Barbier. SEEALSO
Slice Home: http://www.engelschall.com/sw/slice/ AUTHORS
Ralf S. Engelschall rse@engelschall.com www.engelschall.com Denis Barbier barbier@engelschall.com EN Tools 2011-12-18 SLICE(1)
All times are GMT -4. The time now is 01:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy