Rename a file to have Date and Line Count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename a file to have Date and Line Count
# 1  
Old 03-10-2008
Power Rename a file to have Date and Line Count

Hi, I am trying to come with one line command which will rename a file to have Date (MMDDYYYY) and Line Count in the file. Any lead will be appreciated

rgds
bmk
# 2  
Old 03-10-2008
to rename file, use mv
to get date, use date. see man page for info
to get line count, use wc. see man page for info.
you can don't think of that one line command for now.
# 3  
Old 03-10-2008
The simple way as below

>> file content
[root@ganen test]# cat testfile
total 150
drwxr-xr-x 2 root root 4096 Mar 27 2007 bin
drwxr-xr-x 4 root root 1024 Aug 19 2006 boot
drwxr-xr-x 11 root root 5480 Oct 23 22:21 dev
drwxr-xr-x 86 root root 12288 Mar 10 04:03 etc
drwxr-xr-x 6 root root 4096 Jan 30 20:40 home
drwxr-xr-x 11 root root 4096 Mar 27 2007 lib
drwx------ 2 root root 16384 Aug 20 2006 lost+found
drwxr-xr-x 4 root root 4096 Oct 23 22:21 media
drwxr-xr-x 2 root root 0 Oct 23 22:21 misc
drwxr-xr-x 5 root root 4096 Jan 7 2007 mnt
drwxr-xr-x 2 root root 0 Oct 23 22:21 net
drwxr-xr-x 2 root root 4096 May 23 2005 opt
dr-xr-xr-x 99 root root 0 Oct 24 06:20 proc
drwxr-x--- 17 root root 4096 Mar 2 21:44 root
drwxr-xr-x 2 root root 12288 Mar 27 2007 sbin
drwxr-xr-x 2 root root 4096 Aug 19 2006 selinux
drwxr-xr-x 2 root root 4096 May 23 2005 srv
drwxr-xr-x 10 root root 0 Oct 24 06:20 sys
drwxrwxrwt 6 root root 4096 Mar 10 04:02 tmp
drwxr-xr-x 15 root root 4096 Aug 19 2006 usr
drwxr-xr-x 26 root root 4096 Aug 19 2006 var


>> rename testfile to current date and line count
[root@ganen test]# mv testfile `date +%m%d%Y`; wc -l `date +%m%d%Y`
22 03102008


Is that something you want?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed replace to rename each line a file

Have a file in this format This is line one ; line_one This is line two ; line_two This is line three ; line_three This is line four ; line four. I'm trying to make each line a new file called line_one line_two line_three line_four. Tried using split -1 but then I'm back needing to rename... (3 Replies)
Discussion started by: jimmyf
3 Replies

2. Shell Programming and Scripting

Rename the Linux log file to the rotation date

Hi all, could any provide me a solution for the below requirement. I have two files namely abc.log.1 and abc.log.2 The above files have time stamp as Dec 08 and Dec 09 I need to rename the files as abc.log.1_20141208 and abc.log.2_20141209 and move to another bkp directory. Thanks in... (2 Replies)
Discussion started by: bhaskar t
2 Replies

3. Shell Programming and Scripting

BASH function to rename file to last mondays date

I'm trying to create a bash function that will allow me to rename a file name emails.txt to last monday's date renem () { d=`date -d last-monday` mv ~/emails.txt ~/myemails/$d } but i en up wit this error any suggestion mv: target `2014' is not a directory (3 Replies)
Discussion started by: robshal
3 Replies

4. UNIX for Advanced & Expert Users

Script to rename file that was generated today and which starts with date

hello, can someone please suggest a script to rename a file that was generated today and filename that being generated daily starts with date, its a xml file. here is example. # find . -type f -mtime -1 ./20130529_4995733057260357019.xml # this finename should be renamed to this format.... (6 Replies)
Discussion started by: bobby320
6 Replies

5. Shell Programming and Scripting

Multiple File Rename based on pattern - one line

All, I wanted to copy the files From: Daily_XYZ_TEST_1.csv Daily_XYZ_TEST_2.csv Daily_XYZ_TEST_3.csv Daily_XYZ_TEST_4.csv To: Daily_ABC_TEST_1.csv Daily_ABC_TEST_2.csv Daily_ABC_TEST_3.csv Daily_ABC_TEST_4.csv I have tried the rename command but it is not working (5 Replies)
Discussion started by: alfredo123
5 Replies

6. Shell Programming and Scripting

If(Condition) Rename a file with (Date+Time) Stamp

Hi! Please see our current script: #!/usr/bin/ksh if (egrep "This string is found in the log" /a01/bpm.log) then mailx -s "Error from log" me@email.com, him@email.com </a01/bpm.log fi To the above existing script, we need to add the following change: 1) After finding the string,... (7 Replies)
Discussion started by: atechcorp
7 Replies

7. Shell Programming and Scripting

Rename File Based on Created Date

I am trying to rename files based on the created/born date of the file. I Have a total of 4000 files that i am trying to do this with and would like it to be log_yyyymmddhh.gz right now the files are maillog.???.gz. Can anyone point me in the right direction of how to get this done via scipt? ... (4 Replies)
Discussion started by: Paulb
4 Replies

8. Shell Programming and Scripting

Group and count file by date

Hi all, in BIN/SH I need to group and count files by date. Ie: ls -la -rw-r--r-- 1 aaa dba 122 Jul 13 14:28 as1.tmp -rw-r--r-- 1 aaa dba 122 Jul 13 15:27 as2.tmp -rw-r--r-- 1 aaa dba 122 Jul 21 17:04 as3.tmp -rw-r--r-- 1 aaa dba 122 Jul 23 15:45 as4.tmp -rw-r--r-- 1 aaa... (8 Replies)
Discussion started by: ric79
8 Replies

9. Shell Programming and Scripting

copy/rename file as date() unix/shell

File.jpg I want to copy and rename this as 2008-12-02.jpg I tried this copy File.jpg date '%y-%m-%d-%H:%M:%S'.jpg This doesnt work.... what do i do? (1 Reply)
Discussion started by: hdogg
1 Replies

10. Shell Programming and Scripting

Get the line count from 2nd line of the file ?

Hi, I want to get the line count of the file from the 2nd line of the file ? The first line is header so want to skip that. Thanks. (8 Replies)
Discussion started by: smc3
8 Replies
Login or Register to Ask a Question