extract data in a csv file based on a certain field.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract data in a csv file based on a certain field.
# 8  
Old 05-17-2011
That does not give me an output file.

Yes is did. Sorry.

Thanks!
# 9  
Old 06-03-2011
Quote:
Originally Posted by GroveTuckey
I figured out a way to do what I needed in padding 0's.

I do have another question

I need to search in all txt files in a location. But awk only searches the first one and stops.

How do I search *.txt in a location in awk and still have the same results.

Any help would be appreciated.
This would pad that file name with the 0's. Sorry I did not post this before.

Code:
ls *.pull | awk -F'.pull' '{ printf "%s %014s.pull%s\n", $0, $1, $2; }' | xargs -n 2 mv

# 10  
Old 11-02-2011
so this worked until today.

What happened was when the filed has no data in it the command pulls the data. I do not need it to do that.

Here is the line

Code:
awk -F'\t' 'FILENAME~".txt$"{a[$1]=cnt++; next}{if(($12 in a) || ($13 in a)){printf "%05s\n", $2 > $8 ".pull"} }'

Here is a sample data that is complet with no empty fields in question.

5122927 and 0 are the two fields I look at. 12 and 13

Code:
10129953 155 1 155 1 386618 1346 10129953.1 155 00:00.0 85248 5122927 0 FirstName LastName 111 Blah DRIVE  SUN LAKES AZ 85248  9700485     155 1 1 155

Here is a line where the 13th field (0) is empty.

Code:
10129953 156 1 156 1 387964 1255 10129953.1 156 00:00.0 5478 5122928  FirstName LastName 111 Blah MAIN ST APT 4  SAN ALBANS VT 5478  9700486     156 1 1 156

I would like the script to just ignore the blank field.

Thanks in advance!

---------- Post updated at 10:17 PM ---------- Previous update was at 09:40 PM ----------

I would not be opposed to adding a 0 in a blank $13 field.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to extract data from csv file

Hi everyone, I have a csv file which has data with different heading and column names as below. Static Data Ingested ,,,,,,,,,,,,Known Explained Rejections Column_1,column_2,Column_3,Column_4,,Column_6,Column_7,,% Column_8,,Column_9 ,Column_10 ,... (14 Replies)
Discussion started by: Vivekit82
14 Replies

2. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 7 columns having values say column 1,column 2.....column 7 as below along with their values. Name, Address,... (7 Replies)
Discussion started by: Vivekit82
7 Replies

3. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

4. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

5. Shell Programming and Scripting

Matching and Merging csv data fields based on a common field

Dear List, I have a file of csv data which has a different line per compliance check per host. I do not want any omissions from this csv data file which looks like this: date,hostname,status,color,check 02-03-2012,COMP1,FAIL,Yellow,auth_pass_change... (3 Replies)
Discussion started by: landossa
3 Replies

6. Shell Programming and Scripting

Text file to CSV with field data separated by blank lines

Hello, I have some data in a text file where fields are separated by blank lines. There are only 6 fields however some fields have several lines of data as I will explain. Also data in a particular field is not consistently the same size but does end on a blank line. The first field start with... (6 Replies)
Discussion started by: vestport
6 Replies

7. Shell Programming and Scripting

Extract file records based on some field conditions

Hello Friends, I have a file(InputFile.csv) with the following columns(the columns are pipe-delimited): ColA|ColB|ColC|ColD|ColE|ColF Now for this file, I have to get those records which fulfil the following condition: If "ColB" is NOT NULL and "ColD" has values one of the following... (9 Replies)
Discussion started by: mehimadri
9 Replies

8. Shell Programming and Scripting

How to extract data from csv file

Hello everybody, Here is my problem, I don't know anything about shell programming and my boss is actually asking me to develop a shell script in order to get values in a csv file from a specific date. Here is a sample of the csv file : Date;Enchaînement;Titre;Libellé ;calendrier;Heure début;Heure... (11 Replies)
Discussion started by: freyr
11 Replies

9. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

10. Shell Programming and Scripting

Extract data into file with specific field specs

:confused: I have a tab delimited file that I need to extract data from and into a file with specific field specs. Each field has to be a certain amount of characters. So, the name field (from delimited file) might have only 15 characters but needs to be 25 (in new file) so I need to insert spaces... (5 Replies)
Discussion started by: criddel
5 Replies
Login or Register to Ask a Question