![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| (Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script | praka | Shell Programming and Scripting | 6 | 04-15-2009 06:09 AM |
| need inputs on how i can change my script to reduce amount of time the script takes | madhul2002 | Shell Programming and Scripting | 1 | 04-01-2009 07:40 PM |
| Passing the values to the secondary script when it invoked by primary script | venu_eie | Shell Programming and Scripting | 1 | 07-03-2008 06:16 AM |
| create a shell script that calls another script and and an awk script | magikminox | Shell Programming and Scripting | 0 | 06-26-2008 02:50 AM |
| Shell Script: want to insert values in database when update script runs | ring | Shell Programming and Scripting | 1 | 10-25-2007 03:06 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
script help
I have some flat files with time stamp,and some not with time stamp ,I need the files to list with time stamp and non time stamp with sequencial manner.I wrote the shell script to list the files with time stamp ,but non time stamp when use another for loop,its giving more file list.Any advise it should be appereciated.
Code:
Files
=====
file120081218-153431-630.txt
file220081318-153431-630.txt
file320081218-153431-630.txt
file420081218-153431-630.txt
file5.txt
file6.txt
for a in `ls -lrt |awk '{print $9}'|awk '{print substr($0,(index($0,"-"))-1),-8}'|sort -u`
do
echo $a
for a1 in `ls lrt *$a*|awk '{print $9}'`
do
echo $a1
done
done
20081218
file120081218-153431-630.txt
file320081218-153431-630.txt
file420081218-153431-630.txt
20081318
file220081318-153431-630.txt
expecting o/p
20081218
file120081218-153431-630.txt
file320081218-153431-630.txt
file420081218-153431-630.txt
20081318
file220081318-153431-630.txt
file5.txt
file6.txt
Akil |
|
||||
|
Hi ,
I am getting the below error meeage when tring ls -1 | sort -k1.6,1.28 | awk '{ymd=substr($0,6,8); print ymd != prevymd ? (ymd != ".txt" ? "\n"ymd : "")"\n" :"",$0; prevymd=ymd}' syntax error The source line is 1. The error context is {ymd=substr($0,6,8); print ymd >>> != <<< awk: The statement cannot be correctly parsed. Thanks, Akil |
|
||||
|
Need to add paraenthesis...
Code:
ls -1 | /bin/sort -k1.6,1.28 | awk '{ymd=substr($0,6,8); print ((ymd != prevymd) ? (ymd != ".txt" ? "\n"ymd : "")"\n" :"",$0); prevymd=ymd}'
Code:
file5.txt file6.txt 20081218 file120081218-153431-630.txt file320081218-153431-630.txt file420081218-153431-630.txt 20081318 file220081318-153431-630.txt |
|
||||
|
how about below perl script?
Code:
use strict;
my(@arr,%hash);
while(<DATA>){
chomp;
if (/^[^0-9]+([0-9]+)([0-9]{4}[0-9]{2}[0-9]{2})/){
$hash{$2}.=$_."\n";
}
elsif(/^[^0-9]+([0-9]+)/){
push @arr, [$1,$_];
}
}
foreach my $key(sort {$a<=>$b} keys %hash){
print $key,"\n";
print $hash{$key};
print "\n";
}
print join "\n", map {$_->[1]} sort {$a->[0]<=>$b->[0]} @arr;
__DATA__
file10.txt
file320081218-153431-630.txt
file120081218-153431-630.txt
file220081318-153431-630.txt
file420081218-153431-630.txt
file5.txt
file6.txt
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|