Selectively Reformating a file using AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Selectively Reformating a file using AWK
Prev   Next
# 1  
Old 03-23-2009
Computer Selectively Reformating a file using AWK

Dear users,

I am new to AWK and have been battling with this one for close to a week now. Some of you did offer some help last week but I think I may not have explained myself very well. So I am trying again.

I have a dataset that has the following format where the datasets repeat every three lines. So the headings come first and then the packets of data are written out in the file in a similar manner.

col1 col2 col3
col4 col5 col6
col7 col8 col9
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
22 23 24
25 26 27


and I need to change it to the format below:

col1 col2 col3 col4 col5 col6 col7 col8 col9
1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27

Now if that weren't bad enough. Say I only wanted the data from col2, col5 and col8. Or I wanted to select the data from any other column and only that column to be printed out? How would I do this please? The data pattern is regular and repeats itself and I could find out how many lines the file has in total if need be.

Thanks in advance.

Regards,


sda_rr
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selectively extracting entries from FASTA file

I would like to extract all entries containing the following patterns: ccccta & ccccccccc from the following infile: >P39PT-1224_Freq_900 cccctacgacggcattggtaatggctcccgcaagccatctctcttcagccaagg >P39PT-784_Freq_2 cccctacgacggcattggtaatggcacccgcaagccatctctcttccccccccc >P39PT-678_Freq_5... (4 Replies)
Discussion started by: Xterra
4 Replies

2. Shell Programming and Scripting

How to remove spaces from a file selectively?

Hi i have a file in which i am doing some processing. The code is as follows: #!/bin/ksh grep DATA File1.txt >> File2.txt sed 's/DATA//' File2.txt | tr -d ‘ ‘ >> File4.xls As you can see my output is going in a xl file.The output consist of four columns/feilds out of which the first... (20 Replies)
Discussion started by: Sharma331
20 Replies

3. Shell Programming and Scripting

Awk or Perl - to selectively merge two files.

I have two files, these have to be selectively merged into two other files. In addition there will require to be a edit to the last field, where the date format is changed. The first file is a csv file with around 300k lines the data is now nearly 20 years old and I have been asked to move this... (7 Replies)
Discussion started by: gull04
7 Replies

4. Shell Programming and Scripting

Splitting & reformating a single file

I have a bif text file with the following format: d1_03 fr:23 d1_03 fr:56 d1_03 fr:67 d1_03 fr:78 d1_01 fr:35 d1_01 fr:29 d1_01 fr:45 d2_09 fr:34 d2_09 fr:78 d3_98 fr:90 d3_98 fr:104 d3_98 fr:360 I have like thousands of such lines I want to reformat this file based on column 1... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

5. Shell Programming and Scripting

Selectively Find/Replace in a file?

I have a file that is HTML encoded. Each line has something like this on each line.. <href=http://link.com/username.aspx>username </a> more info.. <a href=http://link.com/info1.aspx>info1</a> more code... <a href=http://link.com/info2.aspx>info2</a> I have one goal really.. to clean up the... (2 Replies)
Discussion started by: dragin33
2 Replies

6. Shell Programming and Scripting

Reformating ascii file with awk

Hello, I've a lot of ascii files that I would like to reformat : One of files's column (for exemple $5) contains increasing numbers (see exemple) : $5= 1 1 1 1 1 2 2 2 2 3 3 (2 Replies)
Discussion started by: Caribou
2 Replies

7. UNIX for Dummies Questions & Answers

Removing selectively the last character from a file

Dear Members, Problem is suppose i have 50 lines in a file, 40 lines last character is "\" and the remaining 10 lines are good(i mean these 10 lines do not have "\" character) How can i remove this character from the file. Thanks (1 Reply)
Discussion started by: sandeep_1105
1 Replies

8. Shell Programming and Scripting

awk - reformating rows into columns

looking to do the following... What the data looks like server1 02/01/2008 groups 10 server1 03/01/2008 groups 15 server1 04/01/2008 groups 20 server2 02/01/2008 users 50 server2 03/01/2008 users 75 server2 04/01/2008 users 100 server2 04/01/2008 users 125 What I would like the... (1 Reply)
Discussion started by: jmd2004
1 Replies

9. Shell Programming and Scripting

Selectively splitting a file with C-shell?

I have a rather long csh script that works, but it's terribly ungraceful and takes a while from various loops. I only know enough code to get myself into trouble, so I'm looking for some guidance. I have a large file that is separated at intervals by the same line, like this: ... (2 Replies)
Discussion started by: fusi0n
2 Replies

10. Shell Programming and Scripting

Help on awk.. reformating a file

Hello, I am having a trouble with awk attempting to reformat a two columns file , such as below: 201 84 201 370 201 544 201 600 213 99 213 250 213 431 220 65 220 129 220 338 220 408 220 501 220 550 231 101 231 350 What I need to do is is to add a third column containing a... (4 Replies)
Discussion started by: Martian
4 Replies
Login or Register to Ask a Question
WeekCalculator(3pm)					  LogReport's Lire Documentation				       WeekCalculator(3pm)

NAME
Lire::WeekCalculator - handle different weeknumbering schemes SYNOPSIS
use Lire::WeekCalculator; my $week_calc = new Lire::WeekCalculator(); my $week_no = $week_calc->week_number( $time ); DESCRIPTION
We support three values for LR_WEEK_NUMBERING: ISO (strftime's %V): week starts on monday; W (week starts on monday) and U (week starts on sunday). See strftime(1). CONSTRUCTOR
new( %params ) Creates a new week calculator. The style of week numbering is selected using the "style" parameter. If that parameter is omitted, it defaults to the style set in 'lr_week_numbering' configuration variable. style() Returns the week numbering style used. This will be either "U", "W" or "ISO". week_number( $time ) Returns the week number of $time according the current week numbering scheme. The week number returned is between 1 and 53. week_idx( $time ) Returns the week index of $time according to the week numbering scheme. The week index is Lire specific and is used to normalise computations between different scheme in regards of the first incomplete week of the year. In the ISO case, the week index is always equals to week_number() - 1, for the other style, the week index of the week 0 will be one less than the last week number of the previous year. last_week_of_year($year) Returns the week number of the last week in the year $year. week_start( $year, $week_no ) Returns the epoch time of the first day of week $week_no in year $year when calculated using current style. find_year_week1_start_date($year) Returns the date (epoch) at which the first day of the first week of the year $year starts. strformat() Returns a string that can be used as the format specificier in calls to strftime to print the week number of this style. strfdate() Emulates POSIX::strftime() but picks up the %V if the system strftime doesn't support it. Should be called whenever you use format strings that may contain week-of-the-year-codes. AUTHORS
Joost van Baal <joostvb@logreport.org>, Francis J. Lacoste <flacoste@logreport.org>, Wessel Dankers <wsl@logreport.org> VERSION
$Id: WeekCalculator.pm,v 1.16 2006/07/23 13:16:30 vanbaal Exp $ COPYRIGHT
Copyright (C) 2002 Stichting LogReport Foundation LogReport@LogReport.org This file is part of Lire. Lire 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2006-07-23 WeekCalculator(3pm)