Sponsored Content
Full Discussion: Sort files as pair file
Top Forums Shell Programming and Scripting Sort files as pair file Post 302610489 by drl on Wednesday 21st of March 2012 10:55:01 AM
Old 03-21-2012
Hi.

It's better to state your OS, shell, etc. upfront rather than as an afterthought.

On my system:
Code:
% 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:
Code:
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:
Code:
#!/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:
Code:
$ ./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
This User Gave Thanks to drl For This Post:
 

10 More Discussions You Might Find Interesting

1. AIX

loop through the directory for files and sort by date and process the first file

hello i have a requirement where i have a direcotry in which i get files in the format STOCKS.20080114.dat STOCKS.20080115.dat STOCKS.20080117.dat STOCKS.20080118.dat i need to loop through the directory and sort by create date descending order and i need to process the first file. ... (1 Reply)
Discussion started by: dsdev_123
1 Replies

2. Shell Programming and Scripting

Shellscript to sort duplicate files listed in a text file

I have many pdf's scattered across 4 machines. There is 1 location where I have other Pdf's maintained. But the issues it the 4 machines may have duplicate pdf's among themselves, but I want just 1 copy of each so that they can be transfered to that 1 location. What I have thought is: 1) I have... (11 Replies)
Discussion started by: deaddevil
11 Replies

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

4. Shell Programming and Scripting

How to sort files based on file name having numbers

Right now there is no unix direct commad that can sort the files base on its name having numbers: We can use the following: In case your file name are like: abc-UP018.zip xyz-UP019.zip ls *|sort -t'-' -k2 (2 Replies)
Discussion started by: asifansari
2 Replies

5. Shell Programming and Scripting

Parsing with Name value pair and creating a normalized file

I have url string as follows and I need to parse the name value pair into fields /rows event_id date time payload 1329130951 20120214 22.30.40... (1 Reply)
Discussion started by: smee
1 Replies

6. UNIX for Dummies Questions & Answers

Sort Files based on the number(s) on the file name

Experts I have a list of files in the directory mysample1 mysample2 mysample3 mysample4 mysample5 mysample6 mysample7 mysample8 mysample9 mysample10 mysample11 mysample12 mysample13 mysample14 mysample15 (4 Replies)
Discussion started by: dsedi
4 Replies

7. UNIX for Dummies Questions & Answers

Deleting a file with no corresponding pair

Hi, I am working with 2 sets of files (*csv and *asc) and I wanted to delete asc file with no corresponding csv counterpart. I did tried it manually but its been difficult working with a longer list of files. sample files in directory 20120601.csv 20120601_f1.asc 20120603.csv 20120602_f1.asc... (3 Replies)
Discussion started by: ida1215
3 Replies

8. Shell Programming and Scripting

Parsing a name Value pair file

Hi, I have a file having rows as Row1 : model=.1.3.6.1.4.1.9.1.1047,location=abc, pollgrp=PG_CISCO4, ifindex=3, ip=10.10.10.1,parttype=Interface, devtype=Router,part=GigabitEthernet0/1,ifmtu=1520 Row2 :... (2 Replies)
Discussion started by: mksuneel
2 Replies

9. UNIX for Beginners Questions & Answers

How do I custom sort the files in a directory using the filenames in a text file.?

Hi all, (5 Replies)
Discussion started by: KMusunuru
5 Replies

10. Programming

Calculate ratios for each pair in a given file

Hello, My input file looks like this #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT Individual1 Individual2 Individual3 Individual4 Individual5 Individual6 22 10000 ID1 A ... (0 Replies)
Discussion started by: nans
0 Replies
All times are GMT -4. The time now is 07:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy