Sponsored Content
Full Discussion: Giving format to a file
Top Forums Shell Programming and Scripting Giving format to a file Post 89734 by vgersh99 on Tuesday 15th of November 2005 12:05:28 PM
Old 11-15-2005
given a sample file debian.txt
Code:
Peter;Smith;2005;200508

and a script debian.awk
Code:
BEGIN {
  FS=OFS=";"
  PAT_percent="%"
      # 'LENGTH of the fields'
  split("10 10 8 10", arrL, " ")
      # 'TYPE of the fields"
  split("s s d d", arrT, " ")
}

{
  for(i=1; i <= NF; i++) {
    format=sprintf("%c%c%d%s%s", PAT_percent, (arrT[i] == "s") ? "-" : "0", arrL[i], arrT[i], (i<NF) ? OFS : "\n")
    printf(format, $i)
 }
}

running the script as:
nawk -f debian.awk debian.txt

produces:
Code:
Peter     ;Smith     ;00002005;0000200508


Last edited by vgersh99; 11-15-2005 at 03:00 PM..
 

10 More Discussions You Might Find Interesting

1. Solaris

/sbin/zonename file giving me problems

I'm trying to install the recommended patch cluster on a x86 Solaris 10 box. I get this error: ERROR: /sbin/zonename cannot be found. install_cluster for 10_x86 patch cluster not applied. Exiting. I tried touching the file and it gave a different error of: expected argument.. anyone... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

2. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

3. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

4. Shell Programming and Scripting

Giving input to a c++ file

My C++ program creates a nxn matrix with given value. For e.g if the input is 10 it will creates a matrix of 10x10 now what i want is the script should run program and give input values in a variation of 1000. Say first matrix of 1000 then 2000 , 3000 ..... 10000. I tried using for loop but unable... (2 Replies)
Discussion started by: tonyaim83
2 Replies

5. Shell Programming and Scripting

change the format of a giving file ( a bit challenge) Thank you

Hi, I have a file like this: mgr1.dbf tool.dbf usr.dbf wow19.dbf wow2wow.dbf Can anyone help change the format after each line of reading to: mgr2.dbf # add 1 of *1.dbf tool2.dbf # if not a number exist, make it default to 2 usr2.dbf wow20.dbf # add 1 of *19.dbf wow3wow.dbf ... (5 Replies)
Discussion started by: netbanker
5 Replies

6. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

7. Shell Programming and Scripting

How to execute a script without giving x permission to the file?

How to execute a script with out giving x permission to the file? (7 Replies)
Discussion started by: praveen_b744
7 Replies

8. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

9. Shell Programming and Scripting

Sorting row in a giving file

hi I would like to sort rows in a givin file except the first colomn (or first element of a row) just like the following example file input : 1 3 8 5 2 2 8 1 3 9 8 10 file output : 1 8 5 3 2 8 2 1 3 10 9 8 (4 Replies)
Discussion started by: yassinegoth
4 Replies

10. Shell Programming and Scripting

GetLine fn always giving last line of the file

Hi, Its bit urget for me to complete. pls help me. I am parsing 2 file 1. INDATA(Data file) 2. GRPFIL(Reference) every record in INDATA should be verified with GRP_DATA. I am seeing the output from only the last line of ref file, its not searching all the lines. INDATA sample... (1 Reply)
Discussion started by: hyperion.krish
1 Replies
aegis(5)							File Formats Manual							  aegis(5)

NAME
aegis - meta-data file format DESCRIPTION
The files used by the aegis program all have the same format. Some of the files used by aegis are created and maintained by humans, and some are created an maintained by aegis itself. The various manual entries say which is which. LEXICAL CONSIDERATIONS
Names are any C identifier. Comments are C-style comments (or C++ or shell). Numbers are decimal, octal or hexadecimal, as for C con- stants. Whitespace (spaces, tabs and newlines) are ignored except in strings or as they serve to separate tokens. Strings are C-style strings, and similar to C, sequential string constants are silently catenated together. In addition, there is a style of @string@ which use at-signs (@) for quoting. Unlike the C style of string, newlines are allowed within these strings. To get an at-sign in such a string, double the at-sign. There is no other escape mechanism available. GRAMMAR
The format of all aegis files is described by a yacc (1) grammar. %% file : field_list ; A file contains a field list. field_list : /* empty */ | field_list field ; A field list is zero or more fields. field : NAME '=' value ';' ; A field is set by giving a name and a value. value : NAME | INTEGER | STRING | structure | list ; A value may be a member of an enumeration (NAME), or an integer constant, or a literal string. More complex values may be constructed from these simple values. structure : '{' field_list '}' ; A structure is a grouped list of fields. list : '[' list_body ']' ; list_body : /* empty */ | value_list | value_list ',' ; value_list : value | value_list ',' value A list is a sequential list of values separated by commas. It may be empty, or it may have a trailing comma. SEMANTICS
The types of the values must match those in the definition of the file. See the relevant man pages for more information. Files which are rewritten by aegis will lose any comments placed in them. When time fields are emitted by aegis they are usually followed by a human readable date in a comment. SEE ALSO
aegis(1) a project change supervisor aecattr(5) change attribute file format aecstate(5) change state file format aedir(5) directory structures aegstate(5) aegis state file aepattr(5) project attribute file format aepconf(5) project configuration file format aepstate(5) project state file format aesub(5) available command substitutions aeuconf(5) user configuration file format aeustate(5) user state file format COPYRIGHT
aegis version 4.24.3.D001 Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Peter Miller The aegis program comes with ABSOLUTELY NO WARRANTY; for details use the 'aegis -VERSion License' command. This is free software and you are welcome to redistribute it under certain conditions; for details use the 'aegis -VERSion License' command. AUTHOR
Peter Miller E-Mail: millerp@canb.auug.org.au //* WWW: http://www.canb.auug.org.au/~millerp/ Reference Manual Aegis aegis(5)
All times are GMT -4. The time now is 05:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy