doubt while extracting file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting doubt while extracting file
# 1  
Old 04-27-2010
doubt while extracting file

Hi friends
i am very new to unix.i have one doubt

Last edited by Gopal_Engg; 04-27-2010 at 11:25 AM.. Reason: code tags, please!
# 2  
Old 04-27-2010
Hi,

Try this

Code:
#!/bin/sh

param=$1
curr_date=`date '+%Y_%m_%d'`

first_file=file_$param.txt
last_file=file_$curr_date.txt

ls -ltr file_* | awk '{print $9}' | sort | sed -n "/$first_file/,/$last_file/p"

# 3  
Old 04-27-2010
Files with these names should pretty much sort themselves.

Code:
$ read D
2010_12_03

$ C=$(date '+%Y_%m_%d')

$ ls file_*.txt | sed -n "/$D/,/$C/ p"

file_2010_12_03.txt
file_2010_12_04.txt
file_2010_12_05.txt
file_2010_12_06.txt

or just
Code:
ls file_*.txt | sed -n "/$D/,$ p"

to get everything from the specified date to the newest file

Last edited by Scott; 04-27-2010 at 10:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Doubt with rearranging file through awk

Filename1.xml NO 2012-11-16 02:00:27 20121115/pathname/ asia Filename1.rec YES 2012-11-16 01:20:24 20121115/pathname asia FIleName2.xml YES 2012-11-16 01:20:25 20121115/pathaname asia if the file content are... (6 Replies)
Discussion started by: manas_ranjan
6 Replies

2. Shell Programming and Scripting

Trivial perl doubt about FILE

Hi, In the following perl code: #!/usr/bin/perl -w if (open(FILE, "< in_file")) { while (<FILE>) { chomp($_); if ($_ =~ /patt$/) { my $f = (split(" ", $_)); print "$f\n"; } } close FILE; } Why changing the "FILE" as... (4 Replies)
Discussion started by: royalibrahim
4 Replies

3. Shell Programming and Scripting

awk file reading doubt

Hi, Using this trivial code, I am trying to insert/paste the single column data of a file into the second column (field 2) of a multi-column text file. awk 'FNR==NR {a=$0; next} {$1=$1 OFS a}1' single-column-file multi-column-file Lets consider the single-column-file as 'f2' and multi-column... (1 Reply)
Discussion started by: royalibrahim
1 Replies

4. Programming

Doubt in C programming (copying data from one file to another)

Hello, i'm new to the forum and so am i to C programming. Recently i've gotten a task to create a program that will read an existing .bin file and copy the data to a non existing (so i have to create it) .txt file (some type of conversion) Now, i now how to put the arguments, opening and... (5 Replies)
Discussion started by: Lyric
5 Replies

5. Shell Programming and Scripting

awk script doubt in extracting and comparing uid

Hi, I need to get the value of 'uid' from a line in file f1. For example, in the line below, I need to get the value '150', from the 'anonuid=150' key, and I need to verify that this is a valid uid by checking it against /etc/passwd (i.e) I want to compare this uid, 150 (or more if there are any... (2 Replies)
Discussion started by: royalibrahim
2 Replies

6. Shell Programming and Scripting

sed doubt in extracting

Hi, Can anyone help me in understanding how the below code works? echo "texxt" | sed 's///' gives output exxt, ideally it should give xxt. as this should remove the chars which is not x. echo 'x_a_b_a_c_a_d' | sed 's/.*\(a\)/\1/' gives output as a_d, which should be 'a' as it's the only... (2 Replies)
Discussion started by: royalibrahim
2 Replies

7. Shell Programming and Scripting

Doubt in the .cgi file

Hi, I have attached a .cgi file. Guys could you please let me know what this script is exactly executing with perl. As per as i know it seems that this file is executing to send mails in my box. I am not good in perl. Please check and let me know that it doing in my box. (5 Replies)
Discussion started by: gsiva
5 Replies

8. UNIX for Advanced & Expert Users

NDM File transfer - doubt...?

Hi, I have configured NDM (Connect: Direct) to copy a bunch of files from one server to another. I create a master file contains the list of files which need to copied, and my shell script read the file and send the file one by one thru NDM. The problem is, since the files are very big in size... (0 Replies)
Discussion started by: r_sethu
0 Replies

9. HP-UX

file permissions doubt

hi, i am working in hp ux 11i. 1). the command "ll" (-- long listing) shows the permissions of the files. i like to know.... the first letter of the permissions (prw------- and sometimes i get -r--r--r--) i like to know the first letter 'p' (i know for directories it will be 'd') ... (2 Replies)
Discussion started by: sekar sundaram
2 Replies

10. Programming

Doubt on shadow file

Hi guys, I have a doubt on shadow file ... In the Unix servers in which I am working, I cud see that the shadow file has only one permission set .. tht is read permission for only root user ... (-r--------) .... So my basic doubt here is that how this file is being written then ... only... (4 Replies)
Discussion started by: Sabari Nath S
4 Replies
Login or Register to Ask a Question