Remove the date from the file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove the date from the file
# 1  
Old 01-09-2008
Remove the date from the file

Hi

I am getting the file which is having the format as follows:

set-I
abcxyz20080109
abc20080110

Set-II
abc-20070109
abcxyz-20070110

I need to get only the file name without date as

Set-I
abcxyz
abc

Set-II
abc
abcxyz

Please can any one give me some tips on how to do this?

Thanks
Pradeep
# 2  
Old 01-09-2008
Code:
# sed 's/[0-9]//g' file
abcxyz
abc

# 3  
Old 01-10-2008
Thanks for the reply

I am sorry for not being clear in my question.
If the file name is abc1xyz20080109 then i have to get abc1xyz.

-Thanks
Pradeep
# 4  
Old 01-10-2008
Try this:

Code:
echo $x | sed 's/\(.*\)\([0-9]\{8\}\)/\1/'

# 5  
Old 01-10-2008
Quote:
Originally Posted by jacoden
Try this:

Code:
echo $x | sed 's/\(.*\)\([0-9]\{8\}\)/\1/'

this makes it that the trailing digits should be of length 8

try this

Code:
echo "abcxyz-20070110" | sed 's/\(.*\)\([a-zA-Z-]\)\(.*\)/\1\2/'

# 6  
Old 01-10-2008
Code:
# more file
abc1xyz20080109
abcxyz20080109
abc20080110
abc-20070109
abcxyz-20070110
# sed 's/\(.*[a-zA-Z]\).*/\1/g' file
abc1xyz
abcxyz
abc
abc
abcxyz

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Remove the leading and trailing date from a CSV file

I'm a newbie to shell scripting. Can anyone help with the below requirement ? The leading and trailing date of a files to be removed. 2017-07-12_gmr_tag_log_20170711.csv 2017-07-12_gmr_call_log_20170711.csv 2017-07-12_gmr_outgoing_log_20170711.csv I'm looking for output like... (7 Replies)
Discussion started by: shivamayam
7 Replies

4. Shell Programming and Scripting

Please help, need to create script to remove lines by date in file

Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and... (2 Replies)
Discussion started by: m3pwr
2 Replies

5. Shell Programming and Scripting

How do I take out(remove) the date part in the file name in a script?

Hi All, I need to create links between two directories. have multiple files in a specified location. Source Location ex: /opt/xdm/input/ Target Location ex: /opt/xdm input file names: 1. abc_app.aus.apac.yyyymmdd.dtd 2. abcd_app.aus.apac.yyyymmdd.dtd I need to build a code that reads... (1 Reply)
Discussion started by: kthri_82
1 Replies

6. Shell Programming and Scripting

How to remove the date part of the file?

Hi Gurus, I have file name like: abcd.20131005.dat I need to remove mid part of data final name should be abcd.dat thanks in advance (2 Replies)
Discussion started by: ken6503
2 Replies

7. UNIX for Dummies Questions & Answers

Remove the date portion from file name

hi, I am trying to remove the last field before the period (.) from a list of file names in a directory in a shell script. Below is the list of file names. ENVID_archival_20120214092258.log ENVID_Get_Source_Files_20120214091828.log ENVID_Get_Source_Files_20120214092523.log... (6 Replies)
Discussion started by: Vijay81
6 Replies

8. Shell Programming and Scripting

How to remove '-' for date fields alone in a file

Hi, I have a scenario like, I need to replace a hyphens(-) for date field alone in the file. I have minus(-) sign for other fields it should remain as such, only for date fields hyphens must be removed. Please find the content for the file below: sample.txt: -----------... (4 Replies)
Discussion started by: G.K.K
4 Replies

9. Shell Programming and Scripting

To remove date and duplicate rows from a log file using unix commands

Hi, I have a log file having size of 48mb. For such a large log file. I want to get the message in a particular format which includes only unique error and exception messages. The following things to be done : 1) To remove all the date and time from the log file 2) To remove all the... (1 Reply)
Discussion started by: Pank10
1 Replies

10. HP-UX

How do I take out(remove) the date part in the file name?

Hi Guys here I am again, I have two files in a specified location. Location ex: /opt/xdm/input/ input file names: 1. abc_app.yyyymmdd.dtd 2. abd_app.yyyymmdd.dtd I need to build a code that reads the files from the location based on the oldest date and cuts the date part... (5 Replies)
Discussion started by: ruthless
5 Replies
Login or Register to Ask a Question