Sponsored Content
Top Forums Shell Programming and Scripting Reformat Header of Variable Length Post 302970746 by Scrutinizer on Monday 11th of April 2016 02:23:28 PM
Old 04-11-2016
Another approach.. Try:
Code:
awk -F\; '
  BEGIN {
    split("bc=a: b: c: d: f: g:",L," ")
  }
  !/^@/{
    print
    next
  }
  {
    gsub(/[cd]1:[^,]+,/,x,$2)
    s=$1 FS
    n=split($2,F,",")
    for(i=1; i<=n; i++) {
      if(F[i]!~"^" L[i])
        break
      if(F[i]~/^[cd]1:/)
        continue
      s=s F[i] ","
    } 
    sub(/,$/,";",s)
    print s
  }
' file

Output:
Code:
@S001;bc=a:GGT,b:GGT,c:TTG,d:ACA,f:TCC,g:TGA;
AWTVM...
@S002;bc=a:GGT,b:GTT,c:ATG,d:ACA,f:TCC,g:TGA;
AWTVM...
@S003;bc=a:GGT,b:GTT,c:TTG,d:AGA,f:TGG,g:TGG;
AWTVM...
@S004;bc=a:GGT,b:GTT,c:ATG,d:ACA,f:TGG,g:AGG;
AWTVM...
@S005;bc=a:GGT,b:TGT,c:AGG;
AWTVM...
@S006;bc=a:GGT,b:TGT;
AWTVM...
@S007;bc=a:GGT,b:TGT,c:ATA,d:ACA,f:TCC;
AWTVM...


Last edited by Scrutinizer; 04-11-2016 at 03:33 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. IP Networking

ethernet header length

When i capture a tcp packet (a normal ACK-RST packet), Snort shows me a total packet lenght of 3C(hex) = 60(dez) and an IpLen of 20(dez) and a TcpLen of 20(dez), so the sizeof the Ethernet header should be: TotalPacketLenght-(IpLen+TcpLen), that would be 60-(20+20) = 20, but i thought that the... (4 Replies)
Discussion started by: atmansiddhi
4 Replies

2. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

3. Shell Programming and Scripting

how to reformat a file to 80 byte rec length?

I have a variable length file that needs to be reformatted to 80 byte reclen before I ftp it to a customer. What is the best way to do this? I tried using dd if=inputfile of=outputfile conv=noblock cbs=80, and it almost gives me what I need. The output file needs to be 80-byte records, and the last... (4 Replies)
Discussion started by: cmgarcia
4 Replies

4. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

5. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

6. Shell Programming and Scripting

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

7. UNIX for Dummies Questions & Answers

Delete header row and reformat from tab delimited to fixed width

Hello gurus, I have a file in a tab delimited format and a header row. I need a code to delete the header in the file, and convert the file to a fixed width format, with all the columns aligned. Below is a sample of the file:... (4 Replies)
Discussion started by: chumsky
4 Replies

8. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

9. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

10. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies
SPLIT(1)						    BSD General Commands Manual 						  SPLIT(1)

NAME
split -- split a file into pieces SYNOPSIS
split [-a suffix_length] [-b byte_count[k|m]] [-l line_count] [-p pattern] [file [name]] DESCRIPTION
The split utility reads the given file and breaks it up into files of 1000 lines each. If file is a single dash ('-') or absent, split reads from the standard input. The options are as follows: -a suffix_length Use suffix_length letters to form the suffix of the file name. -b byte_count[k|m] Create smaller files byte_count bytes in length. If ``k'' is appended to the number, the file is split into byte_count kilobyte pieces. If ``m'' is appended to the number, the file is split into byte_count megabyte pieces. -l line_count Create smaller files n lines in length. -p pattern The file is split whenever an input line matches pattern, which is interpreted as an extended regular expression. The matching line will be the first line of the next output file. This option is incompatible with the -b and -l options. If additional arguments are specified, the first is used as the name of the input file which is to be split. If a second additional argument is specified, it is used as a prefix for the names of the files into which the file is split. In this case, each file into which the file is split is named by the prefix followed by a lexically ordered suffix using suffix_length characters in the range ``a-z''. If -a is not speci- fied, two letters are used as the suffix. If the name argument is not specified, the file is split into lexically ordered files named with the prefix ``x'' and with suffixes as above. ENVIRONMENT
The LANG, LC_ALL, LC_CTYPE and LC_COLLATE environment variables affect the execution of split as described in environ(7). EXIT STATUS
The split utility exits 0 on success, and >0 if an error occurs. SEE ALSO
csplit(1), re_format(7) STANDARDS
The split utility conforms to IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
A split command appeared in Version 3 AT&T UNIX. BUGS
The maximum line length for matching patterns is 65536. BSD
August 21, 2005 BSD
All times are GMT -4. The time now is 07:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy