Find the answer to your Linux question:
Results 1 to 6 of 6
Hi All, Suppose, I have a text file... ***Temp.txt*** having: /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1 /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1 /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/10 /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/2 /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/1 /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/2 /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/1 /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/10 /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/2 /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/3 /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/4 /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/1 /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/2 /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/30 /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/4 I want output: both acc. ...
  1. #1
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Sort acc. to numbers(2nd column) with grouping acc. to filenames

    Hi All,

    Suppose, I have a text file... ***Temp.txt*** having:
    /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/10
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/10
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/3
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/4
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/30
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/4

    I want output: both acc. to "Filenames Sorted in ascending order" with sorted version numbers appended at last of each line.

    Like below:
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/10
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/3
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/4
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/10
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/4
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/30
    /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1

    Can this be acheived with using sort command and few string handling...????

    (Hint: This can be possible with only 2 steps...if we can make it possible:-
    change the version no (no..present at the end of each line): say 1 to 000001, 23 to 000023, 334 to 000334 ...etc (if present)..and then do a simple "sort" on the file and finally substitute: "/0*" (multiple 0's) to "/"...but Q? is how can I change 1 to 000001 and 2 digit no. ex: 23 to 000023, 3 digit no: 353 to 000353, 4 digit no: 2316 to 002316 etc........


    Any helps!!!!!!!!!!!

    /Arun S.
    sangal_ak04@yahoo.com
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    This script should do the first job:

    Code:
    #!/bin/sh
    #script1
    
    rm -f tempfile
    
    while read line
    do
      printf "%s/%06d\n" ${line%/*} ${line##/*/} >> tempfile
    done < Temp.txt
    And the script for the finally substitution:

    Code:
    #!/bin/sh
    #script2
    
    while read line
    do
      printf "%s/%d\n" ${line%/*} ${line##/*/}
    done
    Usage: sort tempfile|script2

    You can also combine it to one script.

    Regards

  3. #3
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    No Sir, It didn't work.. Can you pls review it agian........ Arun S.


    [/E*Fare/Users/qabuild/aksutil/P/pawan] $ cat ./delme.sh
    #!/bin/sh
    #script1
    echo -n "enter filename: " && read file
    rm -f tempfile

    while read line
    do
    printf "%s/%06d\n" ${line%/*} ${line##/*/} >> tempfile
    done < $file

    sort tempfile|while read line; do printf "%s/%d\n" ${line%/*} ${line##/*/}; done

    [/E*Fare/Users/qabuild/aksutil/P/pawan] $ cat Temp.txt
    /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/10
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/10
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/3
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/4
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/30
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/4

    [/E*Fare/Users/qabuild/aksutil/P/pawan] $ ./delme.sh
    enter filename: Temp.txt
    /vob/efs/EFare/meta-inf/AFarepf3Form.class.tcl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/acctravel.pl@@/main/pub-int/arne-dev/8
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/baggage.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/3
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/4
    /vob/efs/EFare/Server/combFare.pl@@/main/pub-int/arne-dev/8
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/1
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/2
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/4
    /vob/efs/EFare/Server/combinability.pl@@/main/pub-int/arne-dev/24
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  4. #4
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101

    Wink

    Instead: We can use the line below in 2nd script:

    sort tempfile| sed 's#/00*#/#'


    So, If I combine both of your 1st and 2nd script, it will look like:

    #!/bin/sh

    echo -n "enter filename: " && read file
    rm -f tempfile

    while read line
    do
    printf "%s/%06d\n" ${line%/*} ${line##/*/} >> tempfile
    done < $file

    #While loop in script 2 can be changed to use just "sed"
    sort tempfile| sed 's#/00*\([0-9]*\)$#/\1#'

    Franklin - Thanks a lot for your help.

    Arun
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Arun,

    I got it, printf treats a digit with a preceding 0 as an octal number; printf "%d" 0000010 gives 8.
    To get the correct output you can use the option "%.0f", printf "%.0f" 0000010 gives the correct number.
    Good to know you have it working now.

    Regards

  6. #6
    Linux Newbie Sangal-Arun's Avatar
    Join Date
    May 2006
    Location
    Gurgaon, India + Denver Colorado USA
    Posts
    101
    Your solution was small and perfect.

    Thanks
    Arun

    Quote Originally Posted by Franklin52
    Arun,

    I got it, printf treats a digit with a preceding 0 as an octal number; printf "%d" 0000010 gives 8.
    To get the correct output you can use the option "%.0f", printf "%.0f" 0000010 gives the correct number.
    Good to know you have it working now.

    Regards
    Brgds,

    ARUN SANGAL
    SCM: 1- 720 251 9962
    Email: sangal.ak04@gmail.com
    Email: sangal_ak04@yahoo.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...