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
XCLIP-COPYFILE(1)					      General Commands Manual						 XCLIP-COPYFILE(1)

NAME
xclip-copyfile, xclip-cutfile, xclip-pastefile - copy and move files via the X clipboard SYNOPSIS
xclip-copyfile [-p] FILES... xclip-cutfile [-p] FILES... xclip-pastefile DESCRIPTION
xclip-copyfile copies files into the X clipboard, recursing into directories. xclip-cutfile copies the files, but also deletes them afterwards. -p preserve path formation xclip-pastefile pastes the files out of the clipboard EXAMPLES
Copying a file to a remote host [maggie.lkpg.cendio.se ~]$ echo "A file created on ${HOSTNAME}" > file1 [maggie.lkpg.cendio.se ~]$ xclip-copyfile file1 [sofie.homeip.net ~/doc]$ xclip-pastefile file1 [sofie.homeip.net ~/doc]$ cat file1 A file created on maggie.lkpg.cendio.se Copying an entire tree structure [sofie.homeip.net ~]$ xclip-copyfile doc [maggie.lkpg.cendio.se ~/tmp]$ xclip-pastefile doc/ doc/letter-mom-april.txt doc/file1 doc/letter-dad-march.txt Copying files with preserved path information [maggie.lkpg.cendio.se ~]$ xclip-copyfile -p /etc/sysconfig/grub tar: Removing leading `/' from member names [sofie.homeip.net ~/tmp]$ xclip-pastefile etc/sysconfig/grub [sofie.homeip.net ~/tmp]$ ls etc/sysconfig/grub etc/sysconfig/grub Moving files [sofie.homeip.net ~]$ ls letter-brother-may.txt letter-brother-may.txt [sofie.homeip.net ~]$ xclip-cutfile letter-brother-may.txt [sofie.homeip.net ~]$ ls letter-brother-may.txt ls: cannot access letter-brother-may.txt: No such file or directory [sofie.homeip.net ~]$ cd doc [sofie.homeip.net ~/doc]$ xclip-pastefile letter-brother-may.txt AUTHORS
This manual page was written by Maximilian Gass <mxey@cloudconnected.org> for the Debian project. It may be used for everything else, of course. XCLIP-COPYFILE(1)
All times are GMT -4. The time now is 04:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy