Listing out three fields of data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Listing out three fields of data
# 1  
Old 11-08-2007
Listing out three fields of data

How would I find three different fields in a data file such as first name, last name, credit card number in a particular file?

Thanks in advance for your help
# 2  
Old 11-08-2007
It depends entirely on the format of the data. There is a 93.2% chance that awk will do the job going by the type of posts we get here.
# 3  
Old 11-08-2007
Quote:
Originally Posted by damion
How would I find three different fields in a data file such as first name, last name, credit card number in a particular file?

Thanks in advance for your help
Could someone please give me an example of the string of code I would use to obtain this data? I have no clue how to use AWK. I have been reading but have not found my answer yet.
# 4  
Old 11-08-2007
Quote:
Originally Posted by damion
Could someone please give me an example of the string of code I would use to obtain this data? I have no clue how to use AWK. I have been reading but have not found my answer yet.
As stated by porter, it would depend on the input file.
Something to get you started though:

Code:
cat "yourfile.txt" | awk 'BEGIN {FS = ":"; OFS = " " }  { print $1,$2,$3 }'

Substitute the thing that seperates the fields where I've picked a : character. The OFS bit is choosing how you want it displayed.
The $1,$2,$3 is selecting which fields you want - should be pretty clear.

If your file is seperated by tabs or spaces, you can leave out the "BEGIN {FS = ":"; OFS = " " }" part as that's what it does by default.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing contents of fields

I am often given log files at work in .csv format to work with, normally extracting various fields. I then have to figure out the number of each field so that I can extract that field with cut or awk. Normally I just manually count the fields, based on the field separator. I would like to be... (3 Replies)
Discussion started by: stumpyuk99
3 Replies

2. UNIX for Dummies Questions & Answers

Join command: how to keep all fields in one data

Dear all, I 'd like to ask a question. I have two datasets: a.txt (only has one filed, call 'SNP'), b.txt( has thousands of fields, 1st field call 'SNP'). a.txt: rs9527 rs318567 rs12376 ... b.txt: rs167893 1 2 0 2 1 2 ... rs318567 2 0 2 1 2 0 ... rs12376 0 2 0 2 1 2 ... I... (2 Replies)
Discussion started by: forevertl
2 Replies

3. UNIX for Dummies Questions & Answers

[Solved] How to remove listing of current user cmd from ps -ef listing?

Hi All, Could you please help to resolve my following issues: Problem Description: Suppose my user name is "MI90". i.e. $USER = MI90 when i run below command, i get all the processes running on the system containing name MQ. ps -ef | grep MQ But sometimes it lists... (8 Replies)
Discussion started by: KDMishra
8 Replies

4. Shell Programming and Scripting

Retriving the first line of data from the listing

Hi All, I have a problem of retrieving the first line of data from the listing i got back from this command : ls -l * | awk '{print $9}' | awk -F. '{print $3}' | sort -g the files names are in the folder are like month.dat.201010210400 day.dat.201010210401 year.dat.201010210402 ... (2 Replies)
Discussion started by: chipmuns
2 Replies

5. Shell Programming and Scripting

Match data based on two fields, and append to a line

I need to write a program to do something like a 'vlookup' in excel. I want to match data from file2 based on two fields (where both match) in file1, and for matching lines, add the data from two of the fields from file2 to file1. If anyone knows something in perl or awk that can do this, I'd be... (20 Replies)
Discussion started by: jamessmith01
20 Replies

6. Shell Programming and Scripting

parsing data file picking out certain fields

I have a file that is large and is broken up by groups of data. I want to take certain fields and display them different to make it easier to read. Given input file below: 2008 fl01 LAC 2589 polk doal xx 2008q1 mx sect 25698541 Sales 08 Dept group lead1 ... (8 Replies)
Discussion started by: timj123
8 Replies

7. UNIX for Dummies Questions & Answers

Directorie listing in Human form for data sizes

I have seen it done at my job before, there is a command that will make a notepad and show the directorie path, subfolders, and size of the subfolders? But i dont want it to go lower than 2 levels for example: folder_01 10 GB subfolder_02 10 GB subfolder_03 10 GB... (4 Replies)
Discussion started by: JUSSAN007
4 Replies

8. UNIX for Dummies Questions & Answers

Remove Data from Fields

I would like some sugestions on how to solve the following problem with removing selected data from fields. Each day I receive a file containing 22,000 records that I use a combination of awk and the cut command to remove unwanted fields. This is a work in process as I learn more about awk, sed... (4 Replies)
Discussion started by: greengrass
4 Replies

9. Shell Programming and Scripting

How to change Raw data to Coloumn data fields

Dear All, I have some data file.see below. --------------ALARM CLEARING FROM SubNetwork=ONRM_RootMo,SubNetwork=AXE,ManagedElement=CGSN-------------- Alarm Record ID: 25196304 Event Time: 2006-08-28 13:41:35 Event Type: ... (1 Reply)
Discussion started by: Nayanajith
1 Replies

10. Solaris

Identifying new fields of data

i have hundreds of lines of formatted data with 10 different fields per line. the data is refreshed every few minutes and some fields in some lines may reflect new data. i'm looking for a sample of code that help me to identify those new fields so that i can write them to a file to indicate that... (0 Replies)
Discussion started by: davels
0 Replies
Login or Register to Ask a Question