shell script to sort information in one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to sort information in one file
# 1  
Old 07-27-2011
shell script to sort information in one file

Hi to all,

anyway to create shell script to sort informations from one file and create new file with the sorted values?

from file 30days.out
-bash-3.00# more 30days.out
user/str4@kl.com/INBOX
user/tg1@johor.com/INBOX
user/tg2@kedah.com/INBOX
user/tg3@titangroup.com/INBOX
user/tg4@titangroup.com/INBOX
user/tmnet1/INBOX
user/tmnet2/INBOX
user/tmnet3/INBOX
user/tmnet4/INBOX

to

str4@kl.com
tg1@johor.com
tg2@kedah.com
tg3@titangroup.com
tg4@titangroup.com

---------- Post updated at 12:07 PM ---------- Previous update was at 11:59 AM ----------

thanks, found out myself with old script from one of the guy here before this,

cat 30days.out | cut -d/ -f2 | uniq -c

case closed.
# 2  
Old 07-27-2011
Better (more robust):
Code:
cat 30days.out | cut -d/ -f2 | sort -u

# 3  
Old 07-27-2011
Hi,
If you are familiar with awk you can try this.
Code:
 awk 'BEGIN{FS="/"}{print $2}'  filename


Regards,
Mayur
# 4  
Old 07-27-2011
Quote:
Originally Posted by yazu
Better (more robust):
Code:
cat 30days.out | cut -d/ -f2 | sort -u

Yazu,

why do we need cat here ? Hope the below works

Code:
cut -d/ -f2 30days.out |  sort -u

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to sort a content of a text file using a shell script?

I am new to shell scripting. I am interested how to know how to sort a content of a file using shell scripting. I've attached the 'Input file' and the 'expected output' to this thread. Details provided in the expected output file will provide details on how the sort needs to be done. ... (16 Replies)
Discussion started by: nkarthik_mnnit
16 Replies

2. Shell Programming and Scripting

Help with shell script to extract certain information

Hi, I have a file which I need to programmatically split into two files. All the information in the file before pattern "STOP HERE" is to be stripped and output into one file while everything after "STOP HERE" is to be output into a separate file. I would appreciate help on how to do... (8 Replies)
Discussion started by: PTL
8 Replies

3. UNIX for Dummies Questions & Answers

How can i sort a .txt file without loosing the header information?

Hi, I'm trying to sort 2 different .txt tab delimited files with the command line: sort -k 1b,1 inputfile > outputfile But doing that i'm also sorting the header (that ends at the end of my file). How can i sort a .txt file without sorting the header but conserving the header in the... (3 Replies)
Discussion started by: alisrpp
3 Replies

4. Shell Programming and Scripting

Make shell script get information from the internet

Hello, I am attempting to learn shell for approx. two weeks. So, sorry if I am writing wrong things. Can a shell script get some information for itself from a site? I can't post the site right know, I don't have privileges. But it can be any site that shows the currency between whatever.... (3 Replies)
Discussion started by: alpa8le
3 Replies

5. UNIX for Dummies Questions & Answers

Displaying File Information with du and sort

Hi all, I have a network drive that has a directory named "music". In music I have a ton of folders of artists then albums then songs. I wanted to print out all of the songs ordered by artists then albums. I was trying: ********************* du -ka | sort ********************* ... (4 Replies)
Discussion started by: Imhotep1963
4 Replies

6. Shell Programming and Scripting

Create shell script to extract unique information from one file to a new file.

Hi to all, I got this content/pattern from file http.log.20110808.gz mail1 httpd: Account Notice: close igchung@abc.com 2011/8/7 7:37:36 0:00:03 0 0 1 mail1 httpd: Account Information: login sastria9@abc.com proxy sid=gFp4DLm5HnU mail1 httpd: Account Notice: close sastria9@abc.com... (16 Replies)
Discussion started by: Mr_47
16 Replies

7. Shell Programming and Scripting

Shell script for user login information.

Hi Gurus, I need help in writing a script which should say which user has used or logged in in the server from past one month using FTP or TELNET and the output should be of the form Username Service NumberofTimes Date. Thanks in Advance. ---------- Post updated at 04:01 PM... (1 Reply)
Discussion started by: rama krishna
1 Replies

8. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

9. Shell Programming and Scripting

shell script to sort entries in a file by date and time

Hello All, Need a shell script to sort entries in a file by date and time. Below are the entries in the file, i need to sort it first by the date and then time Note :- Date is in MM/DD/YY format and date comes as the 6th & time comes on 7th coloumns respectively. 150 pbnawldb001-b... (10 Replies)
Discussion started by: ajiwww
10 Replies

10. Shell Programming and Scripting

need Shell script for Sort BASED ON FIRST FIELD and PRINT THE WHOLE FILE WITHOUT DUPLICATES

Can some one provide me a shell script. I have file with many columns and many rows. need to sort the first column and then remove the duplicates records if exists.. finally print the full data with first coulm as unique. Sort BASED ON FIRST FIELD and remove the duplicates if exists... (2 Replies)
Discussion started by: tuffEnuff
2 Replies
Login or Register to Ask a Question