Column wise text adding


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Column wise text adding
# 1  
Old 06-24-2013
Column wise text adding

Hi I have pasted sample data as below:- in data.txt

Please suggest any way out: as the 3rd field is

cat data.txt
Code:
22:37:34 STARTING     abc
22:37:40 FAILURE    sadn
00:06:42 STARTING     asd
00:06:51 FAILURE   ad
02:06:38 STARTING   acs
02:06:46 FAILURE  cz
04:06:35 STARTING   xzc
04:06:43 FAILURE  cz
06:06:32 STARTING    cz
06:06:41 FAILURE  czx
08:06:32 STARTING    cz
08:06:42 FAILURE  c
10:06:33 STARTING    cz
10:06:41 FAILURE  z
12:06:52 STARTING   asd
12:07:00 FAILURE cg_s_test_c
14:06:36 STARTING   zc
14:06:44 FAILURE  c
16:06:35 STARTING    zxc
16:06:44 FAILURE  asd
18:06:42 STARTING    cx
18:06:51 FAILURE  xz
20:06:36 STARTING   cas
20:06:46 FAILURE csa
22:06:36 STARTING   cs
22:06:46 FAILURE cds

and i want to pick data as
Code:
 
cat data.txt | grep STARTING | awk {'print $1, $3'}
cat data.txt | grep FAILURE | awk {'print $1, $3'}

output as below: -
file 1 for starting
Code:
                           
00:06:42 asd
02:06:38 acs
04:06:35 xzc
06:06:32 cz
08:06:32 cz
10:06:33 cz

file 2 for failures
Code:
 
22:37:40 sadn
00:06:51 ad
02:06:46 cz
04:06:43 cz
06:06:41 czx
08:06:42 c

Output needed

Code:
 
started                Failures                   Blah
00:06:42              22:37:40                 asd
02:06:38              00:06:51                 xzc
04:06:35              02:06:46                 xzc  
etc

# 2  
Old 06-24-2013
Code:
awk 'BEGIN {print "Starting Failure Blah"} {printf "%s ", $1; x=$3; getline; printf "%s %s\n", $1, x}' data.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Solaris - Filter columns in text file and adding new column

Hello, I am very now to this, hope you can help, I am looking into editing a file in Solaris, with dinamic collums (lenght varies) and I need 2 things to be made, the fist is to filter the first column and third column from the file bellow file.txt, and create a new file with the 2 filtered... (8 Replies)
Discussion started by: jpbastos
8 Replies

2. UNIX for Dummies Questions & Answers

Adding a column to a text file with row numbers

Hi, I would like to add a new column containing the row numbers to a text file. How do I go about doing that? Thanks! Example input: A X B Y C D Output: A X 1 B Y 2 C D 3 (5 Replies)
Discussion started by: evelibertine
5 Replies

3. Red Hat

How to find a garbage entry in a column wise text file in Linux?

Suppose I have a file containing :- 1 Apple $50 2 Orange $30 3 Banana $10 4 Guava $25 5 Pine@apple $12 6 Strawberry $21 7 Grapes $12 In the 5th row, @ character inserted. I want through sort command or by any other way this row should either on top or bottom. By sort command garbage... (1 Reply)
Discussion started by: Dipankar Mitra
1 Replies

4. UNIX for Dummies Questions & Answers

Adding a column to a text file based on mathematical manipulation

Hi, I have a tab delimited text file with three different columns. I want to add an extra column to the text file. The extra column will be the second column and it will equal third column - 1. How do I go about doing that? Thanks! Input: chr1 788822 rs11240777 chr1 1008567 rs9442372... (2 Replies)
Discussion started by: evelibertine
2 Replies

5. Shell Programming and Scripting

Adding content of two file in a single file column wise

Hi, I am trying to get the file in particular pattern using shell script. I have to add one column to some other file. For example consider two file as below. File1: name1 name2 name3 File2: Add1 age1 Add2 age2 Add3 age3 I want this two file in a single file format something like... (3 Replies)
Discussion started by: diehard
3 Replies

6. UNIX for Dummies Questions & Answers

Adding tags to a specific column of a space delimited text file

I have a space delimited text file with two columns. I would like to add NA to the first column of the text file. Input: 19625 10.4791768259 19700 10.8146489183 19701 10.9084026759 19702 10.9861346978 19703 10.9304364984 Output: NA19625 10.4791768259 NA19700 10.8146489183... (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

Combine Multiple text or csv files column-wise

Hi All I am trying to combine columns from multiple text files into a single file using paste command but the record length being unequal in the different files the data is running over to the closest empty cell on the left. Please see below. What can i do to resolve this ? File 1 File... (15 Replies)
Discussion started by: venky_ibm
15 Replies

8. Shell Programming and Scripting

Adding a column to a text based on file name

Dear all, Does anyone know how I could to add a column of numbers (1s, or 2s, or..., or 6s) to two-column text files (tab-delimited), where the specific number to be added varies as a function of the file naming? Currently, each of my text files has two columns, so the column with the... (12 Replies)
Discussion started by: rlapate
12 Replies

9. UNIX for Advanced & Expert Users

How to compare two text files in column wise?

Hi All, I have two txt files like this File1: no name ---------- 12 aaaa 23 bbbb 55 cccc File2 dname dno ------------ civil 33 mech 55 arch 66 Now i want to compare col1 from File and col2 from File2, if its match i want fetch all columns from... (3 Replies)
Discussion started by: psiva_arul
3 Replies

10. Shell Programming and Scripting

o/p column wise by nawk

hi i have file which hav following entries 1501,AAA,2.00 1525,AAA,2.00 1501,AAA,2.00 1525,AAA,2.00 1501,AAA,3.00 1525,AAA,3.00 1525,AAA,3.00 1501,AAA,3.00 1501,AAA,3.00 i want to have a o/p coloum wise like 1501,AAA,13 1525,AAA,10 here 13 comes as a sum of last colum value... (6 Replies)
Discussion started by: aaysa123
6 Replies
Login or Register to Ask a Question