Aswex
1
Hello,
I am wondering if there is a way to sort file in directory by pair name :
I am looking to get the extension
.txt
above the
.arch
like this if possible
liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt
flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch
liste_NATIVE_HINDCAST_PSY2V3R1_R20120321.txt
flag.NATIVE_HINDCAST_PSY2V3R1.R20120321.arch
liste_VITRINE_PSY4V1R3_R20120321.txt
flag.VITRINE_PSY4V1R3.R20120321.arch
Thanks for your help
drl
2
Hi.
Shuffling:
#!/usr/bin/env bash
# @(#) s1 Demonstrate paste used a shuffle mechanism.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C paste
FILE1=${1-data1}
FILE2=${2-data2}
pl " Input files $FILE1 $FILE2 simulating an ls:"
cat $FILE1 $FILE2
pl " Results, paste (as a kind of shuffle):"
paste -d'\n' $FILE1 $FILE2
exit 0
producing:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
bash GNU bash 3.2.39
paste (GNU coreutils) 6.10
-----
Input files data1 data2 simulating an ls:
flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch
flag.NATIVE_HINDCAST_PSY2V3R1.R20120321.arch
flag.VITRINE_PSY4V1R3.R20120321.arch
liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt
liste_NATIVE_HINDCAST_PSY2V3R1_R20120321.txt
liste_VITRINE_PSY4V1R3_R20120321.txt
-----
Results, paste (as a kind of shuffle):
flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch
liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt
flag.NATIVE_HINDCAST_PSY2V3R1.R20120321.arch
liste_NATIVE_HINDCAST_PSY2V3R1_R20120321.txt
flag.VITRINE_PSY4V1R3.R20120321.arch
liste_VITRINE_PSY4V1R3_R20120321.txt
You can arrange the filenames to suit your desired arrangement.
See man pages for details ... cheers, drl
1 Like
Aswex
3
Thanks DRL for your help,
but I am on ksh (solaris 9) !
Is there a command line instead of a script to make this to work ?
Thanks
drl
4
Hi.
It's better to state your OS, shell, etc. upfront rather than as an afterthought.
On my system:
% ksh
$ paste -d'\n' <( ls -1 l*.txt ) <( ls -1 f*.arch )
liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt
flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch
liste_NATIVE_HINDCAST_PSY2V3R1_R20120321.txt
flag.NATIVE_HINDCAST_PSY2V3R1.R20120321.arch
liste_VITRINE_PSY4V1R3_R20120321.txt
flag.VITRINE_PSY4V1R3.R20120321.arch
For:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0.8 (lenny)
ksh 93s+
Best wishes ... cheers, drl
---------- Post updated at 09:55 ---------- Previous update was at 09:23 ----------
Hi.
This is a more complete listing, closer to your environment:
#!/usr/bin/env ksh
# @(#) s4 Demonstrate paste used as a shuffle mechanism.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C paste
FILE1=${1-data1}
FILE2=${2-data2}
pl " Input filenames:"
ls -1 f*.arch l*.txt
pl " Results, paste (as a kind of shuffle):"
paste -d'\n' <( ls -1 l*.txt ) <( ls -1 f*.arch )
exit 0
producing:
$ ./s4
Environment: LC_ALL = POSIX, LANG = POSIX
(Versions displayed with local utility "version")
OS, ker|rel, machine: SunOS, 5.10, i86pc
Distribution : Solaris 10 10/08 s10x_u6wos_07b X86
ksh M-11/16/88i
paste - ( /usr/bin/paste, Jan 22 2005 )
-----
Input filenames:
flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch
flag.NATIVE_HINDCAST_PSY2V3R1.R20120321.arch
flag.VITRINE_PSY4V1R3.R20120321.arch
liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt
liste_NATIVE_HINDCAST_PSY2V3R1_R20120321.txt
liste_VITRINE_PSY4V1R3_R20120321.txt
-----
Results, paste (as a kind of shuffle):
liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt
flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch
liste_NATIVE_HINDCAST_PSY2V3R1_R20120321.txt
flag.NATIVE_HINDCAST_PSY2V3R1.R20120321.arch
liste_VITRINE_PSY4V1R3_R20120321.txt
flag.VITRINE_PSY4V1R3.R20120321.arch
Best wishes ... cheers, drl
1 Like
Aswex
5
Thank you so much . The command line works fine.