Sponsored Content
Top Forums UNIX for Advanced & Expert Users unix command for terminal - view sequences as a single line? Post 302532966 by kentm on Wednesday 22nd of June 2011 02:00:43 PM
Old 06-22-2011
Thanks!

For these files:

ls
contacts.1.txt contacts.2.txt contacts.3.txt contacts.txt icc.txt ideas.txt notes (Autosaved) notes.txt shownotes_001.txt shownotes_AllShowsShotList_001.txt

that gives me these results:

ls | perl -F"\." -nae 'push @{$a{$F[0]}},$F[1];END{for $i (keys %a){@n=sort {$a <=> $b}@{$a{$i}};print "$i.$n[0]-$n[$#n].$F[2]"}}'

contacts.txt
-3.notes (Autosaved)
.-.icc.txt
-txt
.shownotes_AllShowsShotList_001.txt
-txt
.notes.txt
-txt
.shownotes_001.txt
-txt
.ideas.txt
-txt
.~/notes/ :


What I really am looking for would be this:

contacts.1-3.txt
contacts.txt
icc.txt
ideas.txt
notes (Autosaved)
notes.txt
shownotes_001.txt
shownotes_AllShowsShotList_001.txt


I found another script:

#!/usr/bin/perl
use strict;

#
# lfrms - list frame ranges
# 1.00 01/12/98 erco@3dsite.com
#

$| = 1;

# MAIN
{
my $dir;
my @curdir = ( "." );
my @dirs = ( $#ARGV == -1 ) ? @curdir : @ARGV;

foreach $dir ( @dirs )
{
if ( $#dirs > 0 ) { print "$dir:\n"; }
my @list = split(/\n/, `ls $dir`);
my @last = "";
my $start;
my $pending = 0;

foreach ( @list )
{
if ( /(.*)\.([0-9]*)\.(.*)/ )
{
# NO MATCH ON LAST NAME? SKIP
if ( $1 ne $last[0] || $3 ne $last[2] || ($2-$last[1]) != 1 )
{
# END LAST RANGE
if ( $last[0] ne "" && $last[2] ne "" )
{
if ( $start == $last[1] )
# JUST ONE FRAME? PRINT IT
{ printf("%s.%s\n", $start, $last[2]); }
else
# RANGE? PRINT AS RANGE
{ printf("[%s-%s].%s\n", $start, $last[1], $last[2]); }
}

# START NEW RANGE
printf("%s.", $1);
$start = $2;
$pending = 1;
}

# SAVE FOR NEXT ITER
$last[0] = $1; $last[1] = $2; $last[2] = $3;
}
}
if ( $pending )
{
if ( $start == $last[1] )
# JUST ONE FRAME? PRINT IT
{ printf("%s.%s\n", $start, $last[2]); }
else
# RANGE? PRINT AS RANGE
{ printf("[%s-%s].%s\n", $start, $last[1], $last[2]); }
}
}
}


That returns this:

contacts.[1-3].txt


Which is close to how I'd like the files listed but unfortunately drops the non-sequential files. Would it be easy to modify that command to include the non-sequential files?

Thanks again for offering that.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

run command Unix on a single line

Hi everybody.. I need to enter in bash mode and then run a command and this just in a single command line. I tried : "bash ^M| somecommand" but nothing.. How do I do to simulate the return button just right after the bash command ? Thanks.. (8 Replies)
Discussion started by: Riddick61
8 Replies

2. Shell Programming and Scripting

Is command line invocation of gnome-terminal to run more than one command possible?

Hello, I am trying to learn how to pass something more than a one-command startup for gnome-terminal. I will give an example of what I'm trying to do here: #! /bin/bash # #TODO write this for gnome and xterm USAGE=" ______________________________________________ ${0##*/} run... (0 Replies)
Discussion started by: Narnie
0 Replies

3. UNIX Desktop Questions & Answers

How do you reverse terminal command line to the top?

Hi All, I work on a Linux platform which runs Red Hat (forget which version) and use both korn and bash shells. Is there a way of making the command line appear at the top of the terminal window and any lists, commands or directory names etc to appear below the top, that is to say reverse the... (1 Reply)
Discussion started by: ray_m
1 Replies

4. OS X (Apple)

How to start a new terminal from command line?

Dear All, Anyone knows how to start a new bash terminal from command line? Another question: when I use "open" command (open test.pdf) to open a pdf file, the PDF reader will start up, but cannot associate with that file. Anyone knows why? (1 Reply)
Discussion started by: andrewust
1 Replies

5. UNIX for Advanced & Expert Users

View tiled photo thumbnails in command line

Is there a good way of showing around 4 pictures (fairly large thumbnails) at once on the command line, preferably tiled so that all of them are viewable. I tried using display but I'm not sure how to tile them. I'd also prefer if it was read only so that they cannot be altered in the viewer. ... (1 Reply)
Discussion started by: cue
1 Replies

6. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

7. Shell Programming and Scripting

Can I view doc files from terminal

Sometimes I'm working from terminal for long periods of time and I come across a doc file I don't recognize. I've been trying to figure out how to view it instead of opening up word. I've tried cat but it jumps into binary and my terminal goes nuts. Is there a way I can do this from... (4 Replies)
Discussion started by: syregnar86
4 Replies

8. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

9. OS X (Apple)

A new OSX 10.12.x terminal from the command line.

Hi guys and gals... After much searching on the good ol' internet I could find nothing, so this is the result. ALthough many people seem to have asked this question no-one seems to have a solution so here we go. I need for AudioScope.sh, 'xterm' to run a second program for some of its... (2 Replies)
Discussion started by: wisecracker
2 Replies
ATR_ANALYSIS(1p)						   User Commands						  ATR_ANALYSIS(1p)

NAME
ATR_analysis - analyse a smart card ATR SYNOPSIS
ATR_analysis [ATRstring] DESCRIPTION
ATR_analysis is used to parse the ATR (Answer To Reset) sent by a smart card. The command also tries to find the card model using an ATR database stored in a text file smartcard_list.txt. The smartcard_list.txt file is searched in ./, /usr/local/pcsc/ and /usr/share/pcsc/ directories. Exemple: $ ATR_analysis '3B A7 00 40 18 80 65 A2 08 01 01 52' ATR: 3B A7 00 40 18 80 65 A2 08 01 01 52 + TS = 3B --> Direct Convention + T0 = A7, Y(1): 1010, K: 7 (historical bytes) TB(1) = 00 --> Programming Param P: 0, I: 0 TD(1) = 40 --> Y(i+1) = 0100, Protocol T = 0 ----- TC(2) = 18 --> Work waiting time: 960 x 24 x (Fi/F) + Historical bytes: 80 65 A2 08 01 01 52 Possibly identified card: 3B A7 00 40 18 80 65 A2 08 01 01 52 Gemplus GPK8000 BUGS
Maybe many bugs since I am not a ISO 7816 expert. FILES
smartcard_list.txt SEE ALSO
pcscd(8), pcsc_scan(1) AUTHOR
Ludovic Rousseau <ludovic.rousseau@free.fr> Version: 1.3 October 2005 ATR_ANALYSIS(1p)
All times are GMT -4. The time now is 10:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy