[ask]filtering file to indexing...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ask]filtering file to indexing...
# 1  
Old 06-27-2011
[ask]filtering file to indexing...

dear all,

i have file with format like this
file_master.txt
Code:
20110212|231213|rio|apri|23112|222222
20110212|312311|jaka|dino|31223|543234
20110301|343322|alfan|budi|32131|333311
...

i want filter with output like this
index_nm.txt
Code:
rio|apri
jaka|dino
...

index_years.txt
Code:
20110212
20110212
20110301
...

any idea for this??

Last edited by Franklin52; 06-28-2011 at 03:44 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 06-27-2011
Code:
cut -d'|' -f1 input_file > index_years.txt
cut -d'|' -f3,4 input_file > index_nm.txt

This User Gave Thanks to Shell_Life For This Post:
# 3  
Old 06-27-2011
thx @SL for replaying

i have solve in my case with awk like this

Quote:
awk -F '|' '{ sub("", $4); sub("", $6); print substr($5,0,13),$4 $6 }' input >index.txt
Smilie
# 4  
Old 06-29-2011
Quote:
Originally Posted by Shell_Life
Code:
cut -d'|' -f1 input_file > index_years.txt
cut -d'|' -f3,4 input_file > index_nm.txt

@shell_life
its simple code Smilie nice to use thx for your advice

r.a.r
# 5  
Old 06-29-2011
Code:
awk -F'|' '{print $1  > "file.one"; print $3 "|" $4 > "file.two"}'

This User Gave Thanks to yazu For This Post:
# 6  
Old 06-29-2011
@all
how about if input like this
Code:
20110212|231213|rio|apri|23112|222222
20110214|312311|jaka|dino|31223|543234
20110303|343322|alfan|budi|32131|333311
20110304|342343|tari|niki|32131|333311


and output
file201102.txt
Code:
20110212|231213|rio|apri|23112|222222
20110212|312311|jaka|dino|31223|543234

file201103.txt
Code:
20110303|343322|alfan|budi|32131|333311
20110304|342343|tari|niki|321323|3323422

so i can create cluster file201102.txt willbe sorting all date 201102*
and file201103.txt willbe sorting all date 201103*

thx for your advice
r.a.r

Last edited by Franklin52; 06-30-2011 at 10:56 AM.. Reason: Please use code tags
# 7  
Old 06-29-2011
Code:
awk '{print $0 > "file."  substr($1, 5, 2)}'

Better:
Code:
awk '{print > "file"  substr($0,1,6) ".txt"}'


Last edited by yazu; 06-29-2011 at 12:10 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a file using 2-D indexing system

I have a file and want to split it using a 2-D index system for example if the file is p.dat with 6 data sets separated by ">". I want to set nx=3, ny=2. I need to create files p.dat.1.1 p.dat.1.2 p.dat.1.3 p.dat.2.1 p.dat.2.2 p.dat.2.3 I have tried using a single index and want... (3 Replies)
Discussion started by: kristinu
3 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Filtering records from 1 file based on some manipulation doen on second file

Hi, I am looking for an awk script which should help me to meet the following requirement: File1 has records in following format INF: FAILEd RECORD AB1234 INF: FAILEd RECORD PQ1145 INF: FAILEd RECORD AB3215 INF: FAILEd RECORD AB6114 ............................ (2 Replies)
Discussion started by: mintu41
2 Replies

4. Shell Programming and Scripting

indexing a file

hello guys, I have a file like this: input.dat Push-to-talk No Coonection IP support Support for IP telephony Yes Built-in SIP stack Yes Support via software Yes Microsoft Support for Microsoft Exchange Yes UMA (5 Replies)
Discussion started by: Johanni
5 Replies

5. Shell Programming and Scripting

indexing list of words in a file

Hey all, I'm doing a project currently and want to index words in a webpage. So there would be a file with webpage content and a file with list of words, I want an output file with true and false that would show which word exists in the webpage. example: Webpage content data.html ... (2 Replies)
Discussion started by: Johanni
2 Replies

6. Shell Programming and Scripting

filtering the rows in a file

hi all, please help on this isssue, i have a file which contains something like this and i want to seprate the servers which has vasd.pid ,i need only server names. i want output something like this which vasd.pid . server1 server3 server4 (4 Replies)
Discussion started by: sudharson
4 Replies

7. UNIX for Dummies Questions & Answers

Filtering a file

I have a list of directories looking something like; /usr/local/1/in /usr/local/1/out /usr/local/1/archive /usr/local/2/in /usr/local/2/out /usr/local/2/archive /usr/local/3/in /usr/local/3/out /usr/local/3/archive Is there a way I can filter the out and archive directories so I... (5 Replies)
Discussion started by: JayC89
5 Replies

8. UNIX for Dummies Questions & Answers

Filtering Log file

Hi, Iam trying to filter a log file in the below format |fffff|hhhhh|ffff|dd|mm|yy|hh|min||dd|mm|yy|hh|min the first set of |dd|mm|yy|hh|min is when the application ran the second set of |dd|mm|yy|hh|min when it ended. I will be removing the last of the months in the log file to... (1 Reply)
Discussion started by: baanprog
1 Replies

9. Shell Programming and Scripting

Indexing or Filtering code- Pattern Search by comparing two files

So here is goes to the Gurus of shell programming......I have tried a lot of different ways and its a very challenging code to write but i am enjoying it as i troubleshoot and hopefully someone can provide me a better option....Thank you in advance for your time and support....Much appreciated... ... (12 Replies)
Discussion started by: aavam
12 Replies

10. UNIX for Dummies Questions & Answers

problem in filtering the file

-------------------------------------------------------------------------------- Hi, Plz help me out with this. I have some requirement like this..... I have a file like this... * CS sent email (11.20) CALYPSO 1031276 9076673 CDSHY FAILED Nov 19 2007 7:28AM OASYS: Unable to find CUSTOMER... (0 Replies)
Discussion started by: adityam
0 Replies
Login or Register to Ask a Question