Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Split 1 column into numerous columns based on patterns Post 302957600 by SriniShoo on Tuesday 13th of October 2015 06:51:20 AM
Old 10-13-2015
I know you have got your answer...but since I got he code, I am posting here
Code:
awk '/\"NEW PRODUCT, VERSION 1[.]1\"/ {if(n) {l = l < n ? n : l; print "\"NEW PRODUCT, VERSION 1.1\""; print prod; print head; for(i = 1; i < l-1; i++){print A[i]}; l = 0; n = 0; print ""}; head = ""; val = ""; getline; prod = $0; split(x, A); next}
/\"PRODUCT FIELD\"/ {l = l < n ? n : l; n = 1; next}
n == 1 {head = head == "" ? $0 : (head "\t" $0); n++; next}
n >= 2 {A[(n-1)] = (A[(n-1)] == "") ? $0 : (A[(n-1)] "\t" $0); n++}
END {l = l < n ? n : l; print "\"NEW PRODUCT, VERSION 1.1\""; print prod; print head; for(i = 1; i < l-1; i++){print A[i]}}' Item_List.txt

---------- Post updated at 06:51 AM ---------- Previous update was at 06:47 AM ----------

Code:
awk '/\"NEW PRODUCT, VERSION 1[.]1\"/ {if(n) {l = l < n ? n : l; print "\"NEW PRODUCT, VERSION 1.1\""; print prod; print head; for(i = 1; i < l-1; i++){print A[i]}; l = 0; n = 0; print ""}; head = ""; val = ""; getline; prod = $0; split(x, A); next}
/\"PRODUCT FIELD\"/ {l = l < n ? n : l; n = 1; next}
n == 1 {head = head == "" ? $0 : (head "\t" $0); n++; next}
n >= 2 && NF {A[(n-1)] = (A[(n-1)] == "") ? $0 : (A[(n-1)] "\t" $0); n++}
END {l = l < n ? n : l; print "\"NEW PRODUCT, VERSION 1.1\""; print prod; print head; for(i = 1; i < l-1; i++){print A[i]}}' Item_List.txt

Quote:
Originally Posted by mmab
That works! thanks to those who responded.

---------- Post updated at 11:46 AM ---------- Previous update was at 11:25 AM ----------

One last thing. In the input file there is the possibility that there will be blank spaces for some of the data values. For instance;

Code:
 
"NEW PRODUCT, VERSION 1.1"
PRODUCT_01
"PRODUCT FIELD"
FIELD_X
3333333.0000000
  
4444444.0000000

The output looks like;

Code:
 
"NEW PRODUCT, VERSION 1.1"
PRODUCT_01
"PRODUCT FIELD"
FIELD_X
3333333.0000000
4444444.0000000

Is there a way to keep the blank spaces?
 

10 More Discussions You Might Find Interesting

1. Web Development

split the fields in a column into 3 columns

Have a column "address" which is combination of city, region and postal code like. Format is : city<comma><space>region<space>postal code abc, xyz 123456 All these three city, region and postal code are not mandatory. There can be any one of the above. In that case a nell... (2 Replies)
Discussion started by: rakshit
2 Replies

2. UNIX for Dummies Questions & Answers

split one column into multiple columns

hey guys... Im looking to do the following: 1 2 3 4 5 6 7 8 9 Change to: 1 4 7 2 5 8 3 6 9 Did use | perl -lpe'$\=$.%3?$":"\n"' , but it doesnt give me the matrix i want. (3 Replies)
Discussion started by: zaneded
3 Replies

3. Shell Programming and Scripting

split one column into multiple columns

hey, i have the following data: 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 (7 Replies)
Discussion started by: zaneded
7 Replies

4. Shell Programming and Scripting

Split into columns based on the parameter and use & as delimiter

Here is my source, i have million lines like this on a file. disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=& drc=&mo=&sid=&lang=EN&loc=JPN I want to split this into columns in order to load in database, anything starts with"&mjv=6" as first... (13 Replies)
Discussion started by: elamurugu
13 Replies

5. Shell Programming and Scripting

Split the file based on column

Hi, I have a file sample_1.txt (300k rows) which has data like below: * Also each record is around 64k bytes 11|1|abc|102553|125589|64k bytes of data 10|2|def|123452|123356|...... 13|2|geh|144351|121123|... 25|4|fgh|165250|118890|.. 14|1|abc|186149|116657|......... (6 Replies)
Discussion started by: sol_nov
6 Replies

6. UNIX for Dummies Questions & Answers

Split file based on column

i have file1.txt asdas|csada|130310|0423|A1|canberra sdasd|sfdsf|130426|2328|A1|sydney Expected output : on eaceh third and fourth colum, split into each two characters asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney (10 Replies)
Discussion started by: radius
10 Replies

7. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

8. UNIX for Dummies Questions & Answers

File merging based on column patterns

Hello :) I am in this situation: Input: two tab-delimited files, `File1` and `File2`. `File2` (`$2`) has to be parsed by patterns found in `File1` (`$1`). Expected output: tab-delimited file, `File3`. `File3` has to contain the same rows as `File2`, plus the corresponding value in... (5 Replies)
Discussion started by: dovah
5 Replies

9. UNIX for Beginners Questions & Answers

How to split a column based on |?

Hi all, Newbie here, so please bear over with my stupid question :) I have used far too long time today on figuring this out, so I hope that someone here can help me move on. I have some annotation data for a transcriptome where I want to split a column containing NCBI accession IDs into a... (7 Replies)
Discussion started by: BioBing
7 Replies

10. UNIX for Beginners Questions & Answers

Using awk to split a column into two columns

Hi, I am trying to split the following output into two columns, where each column has Source: Destination: OUTPUT TO FILTER $ tshark -r Capture_without_mtr.pcap -V | awk '/ (Source|Destination): /' | more Source: x.x.x.x Destination: x.x.x.x Source:... (2 Replies)
Discussion started by: sand1234
2 Replies
ESCPUTIL(1)						      Gutenprint Manual Pages						       ESCPUTIL(1)

NAME
escputil - maintain Epson Stylus inkjet printers SYNOPSIS
escputil [ -P printer | -r device ] [ -m model ] [ -S ] [ -C ] [ -p ] [ -u ] [ -c | -n | -a | -i | -d | -o | -s | -l | -M | -h ] [ -q ] DESCRIPTION
escputil is a command line utility to perform various maintenance tasks on Epson Stylus inkjet printers. These tasks include head align- ment, head cleaning, nozzle check, printer identification, and retrieval of ink level from the printer. OPTIONS
escputil accepts the following options: -P, --printer-name=printer Specify the name of the printer to operate on. The default is the default system printer. -r, --raw-device=device Specify the name of the device to write to directly rather than going through a printer queue. You must use this (rather than speci- fying a printer) when retrieving ink levels or identifying the printer, or if you wish to perform head alignment without specifying the printer model. -m, --model=model Specify the precise printer model for head alignment. -u, --new The printer is a new printer (Stylus Color 740 or newer). -S, --short-name Print the short name of the printer with --identify. -C, --choices Specify the number of pattern choices for alignment. -p, --patterns Specify the number of sets of patterns for alignment. -c, --clean-head Clean the print head. This can also be performed from the printer front panel. -n, --nozzle-check Print a nozzle test pattern. Dirty or clogged nozzles will show as gaps in the pattern. If you see any gaps, you should run a head cleaning pass or two. -a, --align-head Align the print head. CAUTION: Misuse of this option may result in poor print quality and/or damage to the printer. You must either specify the printer model with the -m option, or use the raw printer device to allow escputil to detect the printer model. -i, --ink-level Obtain the ink level from the printer. This requires read/write access to the raw printer device. -d, --identify Query the printer for make and model information. This requires read/write access to the raw printer device. -o, --align-color Align the color print head (used by Stylus Color 480 and 580 only). CAUTION: Misuse of this option may result in poor print quality and/or damage to the printer. -s, --status Retrieve printer status. -l, --license Display the license/warranty terms of this program. -M, --list-models List the supported printer models. -h, --help Display a list of all command line options. -q, --quiet Suppress the banner. BUGS
USB-connected printers sometimes fail to identify or return ink levels. You may have to repeat the command. This is probably a timing issue in escputil, not a flaw in the printer. Anything requiring bidirectional communication with the printer (identify, ink levels, or head alignment without specifying the printer model) requires read/write access to the printer port (for example /dev/lp0). This may require these operations to be performed as root. In addition, kernel support is required for bidirectional communication. For Linux version 2.2, CONFIG_PRINTER_READBACK should be enabled; this is called CONFIG_PARPORT_1284 on 2.4 and later kernels. If the printer is performing self-test or head cleaning on power up, the identify and ink level commands will time out, although the printer successfully receives the command. The command will need to be reissued when the printer is quiescent. AUTHORS
Robert Krawitz. COPYRIGHT
Copyright (C) 2000 Robert Krawitz (rlk@alum.mit.edu) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OTHER INFORMATION
The homepage of the Gutenprint project from which this utility was contributed is located at http://gimp-print.sourceforge.net/. SEE ALSO
lp(4), tunelp(8). Version 5.2.9 07 Jul 2012 ESCPUTIL(1)
All times are GMT -4. The time now is 08:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy