Filtering issues with multiple columns in a single file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filtering issues with multiple columns in a single file
# 1  
Old 11-12-2010
Filtering issues with multiple columns in a single file

Hi,

I am new to unix and would greatly appreciate some help.

I have a file containing multiple colums containing different sets of data e.g.

File 1:

John Ireland 27_December_69
Mary England 13_March_55
Mike France 02_June_80

I am currently using the awk command to filter the first 2 columns to one file and the third column to another file e.g.

File 1:

John Ireland
Mary England
Mike France

File 2:

December
March
June


I then use the "paste" command to merge the data from both files so i get the following:

File 3:
John Ireland December
Mary England march
Mike France June


Is there a way to filter all the data to a single file and not to 2 seperate files. I am thinking of using the sed command but im not too sure.

If ive made anything unclear please reply and ill try to explain it better.

Thanks in advance.
# 2  
Old 11-12-2010
Can be done using awk (only tested with GNU awk, might work with nawk too):
Code:
$ cat input.txt
John Ireland 27_December_69
Mary England 13_March_55
Mike France 02_June_80
$ awk -F '[ _]' '{print $1,$2,$4}' input.txt
John Ireland December
Mary England March
Mike France June

# 3  
Old 11-12-2010
Filtering issues with multiple columns in a single file

Hi,

Im using the code but it isnt working. Here is the data i am using and the code that i have typed;

Data in File:

Code:
Tue Nov 9 06:19:46 2010 00:14:53 R7_WRANMOMFJ_72.53
Tue Nov 9 06:30:56 2010 00:26:17 R7_BSIM_72.53

And here is the code i am using

Code:
cat $BUILD_TIMES
awk -F'[ _]' '{print $1,$2,$3,$5,$6,$8}' $BUILD_TIMES >> $FINAL_LIST

$BUILD_TIMES is the file i am referencing and $FINAL_LIST is the file i am putting the filtered data into.

Have i made a mistake with my syntax?

Moderator's Comments:
Mod Comment Please use [CODE][/CODE] tags

Last edited by pludi; 11-12-2010 at 07:33 AM..
# 4  
Old 11-12-2010
What exactly isn't working? What's the desired output and the real output? I'm getting
Code:
Tue Nov 06:19:46 2010 00:14:53 WRANMOMFJ
Tue Nov 06:30:56 2010 00:26:17 BSIM

with your current example.
# 5  
Old 11-12-2010
Hi,

The actual input is

Code:
Tue Nov  9 06:19:46 2010    00:14:53 R7_WRANMOMFJ_72.53
Tue Nov  9 06:30:56 2010    00:26:17 R7_BSIM_72.53

and the desired output is

Code:
Tue Nov 9 2010 00:14:53 WRANMOMFJ
Tue Nov 9 2010 00:26:17 BSIM

When i run the awk command none of the input information is being filtered.

Any suggestions?

Thanks in advance
# 6  
Old 11-12-2010
What version of awk are you using, on which OS? Are there perhaps tabulator characters in the log file (the parts where the space between the columns seem larger)?
# 7  
Old 11-12-2010
I am currently using a program called "Putty" and my OS is vista. I am using the actual command "awk" and no other versions of it. Unfortunately ive only recently been introduced to this programming language.

How would i check for tabulator characters in the log file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining columns from multiple files into one single output file

Hi, I have 3 files with one column value as shown File: a.txt ------------ Data_a1 Data_a2 File2: b.txt ------------ Data_b1 Data_b2 Data_b3 Data_b4 File3: c.txt ------------ Data_c1 Data_c2 Data_c3 Data_c4 Data_c5 (6 Replies)
Discussion started by: vfrg
6 Replies

2. Shell Programming and Scripting

Shell scripting - need to arrange the columns from multiple file into a single file

Hi friends please help me on below, i have 5 files like below file1 is x 10 y 20 z 15 file2 is x 100 z 245 file3 is y 78 z 23 file4 is x 100 (3 Replies)
Discussion started by: siva kumar
3 Replies

3. Shell Programming and Scripting

Filtering first file columns based on second file column

Hi friends, I have one file like below. (.csv type) SNo,data1,data2 1,1,2 2,2,3 3,3,2 and another file like below. Exclude data1 where Exclude should be treated as column name in file2. I want the output shown below. SNo,data2 1,2 2,3 3,2 Where my data1 column got removed from... (2 Replies)
Discussion started by: ks_reddy
2 Replies

4. Shell Programming and Scripting

break from a single list into multiple columns

Hi Guys, I am prety new to the hell scripting world. I am running some grep/cut commands and extracting from a csv file into a list. But the final product I need is that the whole list that I now have has to be broken and separated into columns. Say what I now have extracted is a list of... (6 Replies)
Discussion started by: h_rishi
6 Replies

5. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. Shell Programming and Scripting

Multiple columns to a single column

I have this input: 10 22 1 100 11 22 10 1 50 14 3 1 100 23 3 1 100 24 15 1 100 10 22 5 3 1 33.333 11 22 1 100 It has an inconsistent number of fields but the last field is determined by 100/(NF-2) using awk. I want to take this multiple columned input file and transform so that... (2 Replies)
Discussion started by: mdlloyd7
2 Replies

7. Shell Programming and Scripting

Filtering Multiple variables from a single column

Hi, I am currently filtering a file, "BUILD_TIMES", that has multiple column of information in it. An example of the data is as follows; Fri Nov 5 15:31:33 2010 00:28:17 R7_BCGNOFJ_70.68 Fri Nov 5 20:57:41 2010 00:07:21 R7_ADJCEL_80.6 Wed Nov 10 17:33:21 2010 00:01:13 R7_BCTTEST3_80.1X... (7 Replies)
Discussion started by: crunchie
7 Replies

8. Shell Programming and Scripting

Single column to multiple columns in awk

Hi - I'm new to the awk programming language. I'm trying to print a single column of data to several columns, and I found an article on iTWorld.com (ITworld.com - Printing in columns). It looks like the mkCols2 script is very close to what I need to do, but it looks like the end of the code... (2 Replies)
Discussion started by: astroDave
2 Replies

9. UNIX for Dummies Questions & Answers

single column to multiple columns

Hello, I have a single column of data that I would like to cut/print (with awk or ...) into multiple columns at every empty row (or common character). Input: 5.99123 5.94693 7.21383 5.95202 0.907935 5.99149 6.08427 0.975774 6.077 Output: 5.99123 5.95202 6.08427 5.94693... (7 Replies)
Discussion started by: agibbs
7 Replies

10. Shell Programming and Scripting

Filtering multiple entries in a file

Hi, I have a requirement to filter multiple entries in a text file. Entries are a pair of 2 lines .Like line1 line2 ....... ........ Here line1, line2 consist of one pair. line1 and line2 contain different data. There can be multiple entries for the same pair. And there can be 'n' such... (2 Replies)
Discussion started by: suman_jakkula
2 Replies
Login or Register to Ask a Question