sort txt file using another file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort txt file using another file
# 1  
Old 12-10-2007
sort txt file using another file


i have a file looks like :


and another file like :

: represents a line identical in the same file FILEA and FILEB:

i want to sort the first file ( FILE A) like :


thanks Smilie
# 2  
Old 12-10-2007

This might get you close: FILEA < FILEB
while read left
  right=`grep $match $1 | cut -d ',' -f 2`
  if [ -z "$right" ]
    echo "$left"
    echo "${left},${right}"

# 3  
Old 12-11-2007

thanks for your help but this script only prints the first column of FILEB and don't sort the file i don't know if i do mistake but i try it i don't get result.


any help plz
# 4  
Old 12-11-2007
I changed variable names halfway through by mistake. Replace the following line:
right=`grep $match $1 | cut -d ',' -f 2`

With this line:
right=`grep $left $1 | cut -d ',' -f 2`

(ie, change the word $match to $left)
You didn't say how you need it sorted so I left that part out. But if you sort FILEB how you want it before you pipe it in, it'll come out in the same order
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

2. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

3. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

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

5. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

6. Shell Programming and Scripting

bash script to sort a txt file

I am writing a script to write to and a sort txt file. After I sort the file I want to add 2 to each line of the file. My script thus far is #!/bin/bash cat > /ramdisk/home/stux/unsortedints.out COUNT=0 FILE =/ramdisk/home/stux/unsortedints.out for i in {1..100} do NUMBER = $ echo $NUMBER... (3 Replies)
Discussion started by: puttyirc
3 Replies

7. Shell Programming and Scripting

PERL:How to convert numeric values txt file to PACKED DECIMAL File?

Is there any way to convert numeric values txt file to PACKED DECIMAL File using PERL. Regards, Alok (1 Reply)
Discussion started by: aloktiwary
1 Replies

8. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

9. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" it works... (2 Replies)
Discussion started by: ash22
2 Replies

10. Shell Programming and Scripting

Sorting problem "sort -k 16,29 sample.txt > output.txt"

Hi all, Iam trying to sort the contents of the file based on the position of the file. Example: $cat sample.txt 0101020060731 ## Header record 1c1 Berger Awc ANP20070201301 4000.50 1c2 Bose W G ANP20070201609 6000.70 1c2 Andy CK ANP20070201230 28000.00... (3 Replies)
Discussion started by: ganapati
3 Replies
Login or Register to Ask a Question