make 2 column in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting make 2 column in file
# 8  
Old 07-03-2010
Here's a Perl one-liner:

Code:
$ 
$ 
$ cat 510095000029221.log1
        Acct-Status-Type = Stop (2)
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
======
Sun Jun 20 00:01:23 2010
        Event-Timestamp = "Jun 20 2010 00:05:40 WIT"
Sun Jun 20 00:02:46 2010
        Event-Timestamp = "Jun 20 2010 00:07:03 WIT"
Sun Jun 20 00:03:23 2010
        Event-Timestamp = "Jun 20 2010 00:07:41 WIT"
Sun Jun 20 00:04:27 2010
        Event-Timestamp = "Jun 20 2010 00:08:45 WIT"
Sun Jun 20 00:06:00 2010
        Event-Timestamp = "Jun 20 2010 00:10:17 WIT"
Sun Jun 20 00:07:19 2010
        Event-Timestamp = "Jun 20 2010 00:11:36 WIT"
Sun Jun 20 00:08:40 2010
        Event-Timestamp = "Jun 20 2010 00:12:58 WIT"
Sun Jun 20 00:09:39 2010
        Event-Timestamp = "Jun 20 2010 00:13:56 WIT"
Sun Jun 20 00:11:18 2010
        Event-Timestamp = "Jun 20 2010 00:15:35 WIT"
Sun Jun 20 00:15:59 2010
        Event-Timestamp = "Jun 20 2010 00:20:16 WIT"
Sun Jun 20 00:16:36 2010
$ 
$ 
$ perl -lne 'chomp; if ($append) {$x[$i++] .= " $_"}
           elsif (/^=+$/) {$append=1; $i=0} else {push @x, $_}
           END {print for (@x)}' 510095000029221.log1
        Acct-Status-Type = Stop (2) Sun Jun 20 00:01:23 2010
                                           Event-Timestamp = "Jun 20 2010 00:05:40 WIT"
        Acct-Status-Type = Start (1) Sun Jun 20 00:02:46 2010
                                           Event-Timestamp = "Jun 20 2010 00:07:03 WIT"
        Acct-Status-Type = Stop (2) Sun Jun 20 00:03:23 2010
                                           Event-Timestamp = "Jun 20 2010 00:07:41 WIT"
        Acct-Status-Type = Start (1) Sun Jun 20 00:04:27 2010
                                           Event-Timestamp = "Jun 20 2010 00:08:45 WIT"
        Acct-Status-Type = Stop (2) Sun Jun 20 00:06:00 2010
                                           Event-Timestamp = "Jun 20 2010 00:10:17 WIT"
        Acct-Status-Type = Start (1) Sun Jun 20 00:07:19 2010
                                           Event-Timestamp = "Jun 20 2010 00:11:36 WIT"
        Acct-Status-Type = Stop (2) Sun Jun 20 00:08:40 2010
                                           Event-Timestamp = "Jun 20 2010 00:12:58 WIT"
        Acct-Status-Type = Start (1) Sun Jun 20 00:09:39 2010
                                           Event-Timestamp = "Jun 20 2010 00:13:56 WIT"
        Acct-Status-Type = Stop (2) Sun Jun 20 00:11:18 2010
                                           Event-Timestamp = "Jun 20 2010 00:15:35 WIT"
        Acct-Status-Type = Start (1) Sun Jun 20 00:15:59 2010
                                           Event-Timestamp = "Jun 20 2010 00:20:16 WIT"
        Acct-Status-Type = Stop (2) Sun Jun 20 00:16:36 2010
                                  
        Acct-Status-Type = Start (1)
                                  
        Acct-Status-Type = Stop (2)
                                  
$ 
$ 
$ 

tyler_durden
# 9  
Old 07-04-2010
The inevitable awk Smilie
Code:
awk '!i{A[NR]=$0}i{print A[i]"\t"$0;i++}/^=====/{i=1;m=NR-1}END{for (;i<=m;i++)print A[i]}' infile



---------- Post updated at 09:00 ---------- Previous update was at 08:38 ----------

ksh93/bash:
Code:
paste <(sed '/^=====/,$d' infile) <(sed '1,/^=====/d' infile)

This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 07-04-2010
Thanks, working Great as I need
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete 'duplicated' column values and make a delimited file too?

Hi, I have the following output from an Oracle SQL statement and I want to remove duplicated column values. I know it is possible using Oracle analytical/statistical functions but unfortunately I don't know how to use any of those. So now, I've gone to PLAN B using awk/sed maybe or any... (5 Replies)
Discussion started by: newbie_01
5 Replies

2. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

3. Shell Programming and Scripting

using AWK to make four column to one column

Gurus, I have file contain following line. ,0113955056,,XAgent-Suspend ,0119418233,,XAgent-Suspend ,0102119078,,XAgent-Suspend I want to make it one column file. How to do this using awk? Can anyone help with 'awk' 0113955056 0119418233 0102119078 (5 Replies)
Discussion started by: thepurple
5 Replies

4. Shell Programming and Scripting

Calculate data and make it into new column using awk

Hi everyone, just some simple question... i've been using a awk script to calculate my data... i have 3 files: file a1.txt: 2 3 4 5 3 4 file a2.txt: 4 5 6 7 8 (1 Reply)
Discussion started by: yat
1 Replies

5. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

6. Emergency UNIX and Linux Support

awk- add columns and make new column and save as newfile

Hi, I have file as below: 5 6 7 4 8 9 3 5 6 output needs to be another file with 4th column as $1+$2 and 5th column as $3+$4. sample output file 5 6 7 11 18 4 8 9 12 21 3 5 6 8 14 Anybody have answer Thanks in advance (3 Replies)
Discussion started by: vasanth.vadalur
3 Replies

7. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

8. Shell Programming and Scripting

trying to make an AWK code for ordering numbers in a column from least to highest

Hi all, I have a large column of numbers like 5.6789 2.4578 9.4678 13.5673 1.6589 ..... I am trying to make an awk code so that awk can easily go through the column and arrange the numbers from least to highest like 1.6589 2.4578 5.6789 ....... can anybody suggest, how can I do... (5 Replies)
Discussion started by: ananyob
5 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

10. Shell Programming and Scripting

repeated column data filter and make as a row

I need to get the output in row wise for the repeated column data Ex: Input: que = five ans = 5 que = six ans = 6 Required output: que = five six ans = 5 6 Any body can guide me?"""""" (2 Replies)
Discussion started by: vasanth_vadalur
2 Replies
Login or Register to Ask a Question