Visit Our UNIX and Linux User Community

Issue while splitting a row of record

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue while splitting a row of record
# 8  
Old 09-23-2009
$ cat file
Account_Id Date Id Balance
44 9 1000.00 30 15-10-2173 10 1000.00 42 15-10-2173 10 1200.00 53 01-01-2008 10 1200.00

The idea is to split fields in group of 4. If the second field of that group is not a date, offset the field order by one.

        # if every second field is a not a date
        if(i+n==(2+(j*4)) && $i !~ /^[0-9][0-9]-/){
            dummy="            "    # set space for missing date
            n+=1                    # offset fields order by one
        sep=" "
        if(!((i+n)%4)){             # line break every 4 field
        printf dummy $i sep

Yield the following result:
$ awk -f aa.awk file
44             9 1000.00
30 15-10-2173 10 1000.00
42 15-10-2173 10 1200.00
53 01-01-2008 10 1200.00

Previous Thread | Next Thread
Test Your Knowledge in Computers #49
Difficulty: Easy
A USB hard drive is considered to be a primary storage device for personal computers.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

2. Shell Programming and Scripting

How to place Record in a row as a column name?

Hi, I want to know how to place a particular field availble in a record as the columnname. Name,Sam,Age,13,School, StJohn Name,Rita,Age,12,School, StMichael, Name,John,Age,14,School, StAnthony I want the output as Name Age School Sam 13 StJohn Rita 12 StMichael John 14... (6 Replies)
Discussion started by: sidnow
6 Replies

3. Shell Programming and Scripting

Exclude the header row while splitting the file

Hi All, i have script like ... "TYPE_ID" "ID" "LIST_ID" "18" "52010" "1059" "18" "52010" "1059" "18" "52010" "1059" "18" "52010" "1059" i am using the below code it's not taking the header row. awk -F"\t" -v file=test1.txt -v file1=test2.txt ' { if(... (7 Replies)
Discussion started by: bmk
7 Replies

4. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

5. Shell Programming and Scripting

Need help splitting huge single record file

I was given a data file that I need to split into multiple lines/records based on a key word. The problem is that it is 2.5GB or bigger and everything I try in perl or sed causes a Segmentation fault. Can someone give me some other ideas. The data is of the form:... (5 Replies)
Discussion started by: leolson
5 Replies

6. Shell Programming and Scripting

Splitting data from one row as multiple columns

Hi I have a file containing some data as follows: 11-17-2010:13:26 64 4 516414 1392258 11-17-2010:13:26 128 4 586868 695603 11-17-2010:13:26 256 4 474937 1642294 11-17-2010:13:32 64 4 378715 1357066 11-17-2010:13:32 128 4 597981 1684006 ... (17 Replies)
Discussion started by: annazpereira
17 Replies

7. UNIX for Dummies Questions & Answers

Record splitting with AWK

Hi all ! I need your help as quick as possible. My input file like this: bạc těnh ( 薄情) 1 . 薄情な.2. 夫婦或いは男女の不貞を指す。 bách (百,迫)1.100ドソ. tr a m b a c ともいう. 2.柏(カヽしわ)・ 3.圧迫する.4.差し迫った, My propose is take the value in the firt bracket. I used the command like : ...if (index(... (6 Replies)
Discussion started by: maixu134
6 Replies

8. Shell Programming and Scripting

Split a record ( in a row) and make it as new row

Hi All, The following is the scenario id name -------------- 1 William;Johnson 2 Azim;Abdul 3 Grasim . . etc.... I need the following output id name -------------- 1 William 1 Johnson 2 Azim (2 Replies)
Discussion started by: kottursamy
2 Replies

9. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies

10. UNIX for Advanced & Expert Users

Issue with Splitting of file

HI! All Iam running this script ro split the file ,attact a timesatmp to it and then conver it to .tmp extension cd /home/staff/thussain Prefix=Z_PRICE_NEW_`date "+%Y%m%d%H%M%S"` split -3000 -a 5 /home/staff/thussain/Z_PRICE_NEW.txt $Prefix find . -name "$Prefix*" -print | { while read... (6 Replies)
Discussion started by: mohdtausifsh
6 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)

Featured Tech Videos