Extract column data from File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract column data from File
# 1  
Old 10-11-2007
Extract column data from File

I have a file containing the lines similar to the following entries:

File1.txt:
.....
-rw-r--r-- 1 root staff 4110 Aug 7 17:02 XXX_OrderNum1_date1_time1.txt
-rw-r--r-- 1 root staff 4110 Aug 7 17:02 XXX_OrderNum2_date2_time1.txt
-rw-r--r-- 1 root staff 4110 Aug 7 17:02 XXX_OrderNum1_date2_time1.txt
....

My goal is to prepare a file which contains all the orders that occured more than once.

Like File2.txt:
OrderNum1 = 2 times

How can we achieve this?
# 2  
Old 10-11-2007
Code:
$ awk '{print $NF}' tmp/file.txt | sed 's/^[^_]*_\([^_]*\)_.*$/\1/' | sort | uniq -c | awk '$1 !~ /^1$/ {printf( "%s = %s time(s)\n", $2, $1 )}'

Cheers,
ZB
# 3  
Old 10-11-2007
Code:
awk 'BEGIN{FS="_"}{a[$2]++}
     END{for (i in a) print i " : " a[i]}' "file"

# 4  
Old 10-11-2007
Just the duplicates...
Code:
cut -d _ -f2 file1.txt | sort | uniq -d

Duplicates with count...
Code:
cut -d _ -f2 file1.txt | sort | uniq -c | awk '$1>1&&$0=$2 " = " $1 " times"'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

Change data in one column with data from another file's column

Hello, I have this file outputData: # cat /tmp/outputData __Capacity^6^NBSC01_Licences^L3_functionality_for_ESB_switch __Capacity^2100^NBSC01_Licences^Gb_over_IP __Capacity^1837^NBSC01_Licences^EDGE_BSS_Fnc __Capacity^1816^NBSC01_Licences^GPRS_CS3_and_CS4... (1 Reply)
Discussion started by: nypreH
1 Replies

3. UNIX for Dummies Questions & Answers

Extract column data

I have a file which extracts data from an HTML file For Eg HTML file contains: New York;ABC;145;Yes;YES;No New York;BCD;113;Yes;YES;No New York;NAS;63;Yes;YES;No ------------------------ London-48;CBT;16;Yes;YES;No London-48;CME;17;Yes;YES;No London-48;EUR;52;Yes;YES;No... (3 Replies)
Discussion started by: newkid.7955
3 Replies

4. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

5. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

6. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

7. Shell Programming and Scripting

Need to extract data from Column having variable length column

Hi , I need to extract data from below mentioned data, having no delimiter and havin no fixed column length. For example: Member nbr Ref no date 10000 1000 10202012 200000 2000 11202012 Output: to update DB with memeber nbr on basis of ref no. ... (6 Replies)
Discussion started by: ns64110
6 Replies

8. UNIX for Dummies Questions & Answers

Extract alphahumeric data from a column

Hi Unix Gurus, I am newbie to UNIX. I have a file test.txt with the follwing data aa90558 bb72962 cc08342 xy112233 yz25341 aa372099 cc34590231 bb880011 testfil Whatisit00 1234556 testfile2test I want to output only the items with two alpha followed by 5 numeric (ex aa90558 or... (2 Replies)
Discussion started by: SalM
2 Replies

9. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

10. Shell Programming and Scripting

how to extract a data from a column?

Hi All, Consider the below column, say this is the 4th column in a file PROV_STATS:::919900546978::Nokia 6600 PROV_STATS:::919900546978::Nokia 6600 PROV_STATS:::919900546978::Nokia 6600 I wanted to extract only 919900546978 from the 4 th cloumn using unix scripting? Kindly help (8 Replies)
Discussion started by: Balaji Sukumara
8 Replies
Login or Register to Ask a Question