how to parse contents in a column in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to parse contents in a column in a file
# 1  
Old 06-03-2009
how to parse contents in a column in a file

hi all,

i am facing this problem ,please help.

suppose a file contains conetnts as below:

john itemspurchased/date
john itempurchased/date
james itempurchased/date
john items purchsed/date


so here i want to store john only once in a variable but retreive his 3 corresponding data (items purchesd with date). i. e i want to store each value in the 1st column once only.

need ur help urgently.....
thanks in advance
# 2  
Old 06-03-2009
Are you expecting something like this ??
Code:
awk '{a[$1]=a[$1]"\n"$2} END { for (i in a){ print i "-->" a[i]} }' inputfile.txt

# 3  
Old 06-03-2009
the above command is showing errors when used in perl script.

is there a way to do this using perl script.
# 4  
Old 06-03-2009
show your Perl script. Or is it you haven't got one?
# 5  
Old 06-03-2009
Tools Homework?

Whenever someone specifically requests a mode for solution - in this case to provide a perl script - is a big signal that this is likely homework.

Our Rules do not allow assistance with homework.
The UNIX and Linux Forums - Forum Rules
# 6  
Old 06-03-2009
Computer

thanks for your solution....it worked and every doubt is a homeworkSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace the contents of first column of file "X" with second Column of file "X" in file "Y"

Hi! I am having 02 files. In first file" X" I am having 02 Columns TCP-5100 Sybase_5100 TCP-5600 Sybase_5600 Second file "Y" for example-- :services ( :AdminInfo ( :chkpf_uid ("{A2F79713-B67D-4409-83A4-A90804E983E9}") :ClassName (rule_services) ) :compound ()... (12 Replies)
Discussion started by: shahid1632
12 Replies

2. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

4. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

5. Shell Programming and Scripting

Parse file contents in perl...

Hi, I have the file like this: #Contents of file 1 are: Dec 10 12:33:44 User1 Interface: Probe Dec 10 12:33:47 uSER1 SOME DATA Dec 10 12:33:47 user1 Interface: MSGETYPE Dec 10 12:34:48 user1 ID: 10. Dec 10 12:33:55 user1 Interface: MSGTYPE Dec 10 12:33:55 user1 Id: 9 ... (1 Reply)
Discussion started by: vanitham
1 Replies

6. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

7. Shell Programming and Scripting

Parse 1 column and add 2nd column

I'm racking my brain on this one! :( I have a list like this: Paul 20 Paul 25 Paul 30 Frank 10 Julie 15 Julie 13 etc, etc... I've been trying to figure out a way to have the output display the name in the first column ONCE and add the numbers in the second column and display that... (2 Replies)
Discussion started by: sdlennon
2 Replies

8. Shell Programming and Scripting

how do i parse by specific column?

I have a log file with 13 columns. The 12th column contains the status code (example 200, 404, 500, 403, etc.) I want to remove all 200 status lines. so... 1. remove all the lines in which the 12th column has a 200. 2. display only the lines in which the 12th column shows a 500. ... (2 Replies)
Discussion started by: kmaq7621
2 Replies

9. Shell Programming and Scripting

Unix shell script to parse the contents of comma-separated file

Dear All, I have a comma-separated file. 1. The first line of the file(header) should have 4 commas(5 fields). 2. The last line of the file should have 1 comma(2 fields). Pls help me in checking this condition in a shell script. And the number of lines between the first line and last... (11 Replies)
Discussion started by: KrishnaSaran
11 Replies

10. Shell Programming and Scripting

copy contents of one column in another

Hi, I want to pick contents of a column in a file and copy the contents of this to other column. awk can be used for this, but the number of fields are higher so awk will not help. Any other way to do this. e.g following file has some contents a follows a,b,c,d,e,f,9,0 i need... (4 Replies)
Discussion started by: raman1605
4 Replies
Login or Register to Ask a Question