The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
problem cutting finalight Shell Programming and Scripting 6 05-20-2008 09:53 PM
CUT command - cutting characters from end of string JWilliams AIX 2 01-28-2008 09:12 AM
cutting terms5 UNIX for Dummies Questions & Answers 1 03-15-2006 01:33 AM
cutting part of string dhaval_khamar Shell Programming and Scripting 3 07-25-2005 11:18 AM
cutting out the last field bcheaib Shell Programming and Scripting 2 06-07-2005 05:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-21-2004
lesstjm lesstjm is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 59
Question Cutting Up a String

I have a file name coming in as such


<string>_YYYYMMDD.DAT


The string could be anything. I want to cut out the date and put it in a variable. Can someone help me with this?
  #2 (permalink)  
Old 09-21-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813
try:

Code:
#!/bin/ksh
filename="stuff_20040903.DAT"
filedate=${filename%.*}
filedate=${filedate#*_}
echo $filedate

exit

  #3 (permalink)  
Old 09-21-2004
farzolito farzolito is offline
Registered User
  
 

Join Date: Nov 2001
Location: Lille, France
Posts: 20
hi,

you can test with this command :

ls *.dat | sed 's/_/./g'|awk -F . '{print $2}'

the result of this command give you the date.
  #4 (permalink)  
Old 09-21-2004
lesstjm lesstjm is offline
Registered User
  
 

Join Date: Nov 2001
Posts: 59
Thanks

thanks for your help
  #5 (permalink)  
Old 09-21-2004
encrypted's Avatar
encrypted encrypted is offline Forum Advisor  
Registered User
  
 

Join Date: Feb 2004
Location: Oslo, Norway
Posts: 219
Quote:
I want to cut out the date and put it in a variable

Quote:
<string>_YYYYMMDD.DAT
Assuming that you have got only DAT extention files to process:


#!/bin/bash

FILES=`ls -1 *DAT`
for file in $FILES
do
ls -1 $file |cut -f2 -d _ | cut -f1 -d . >> date_list
done
DATE_VAR=`cat date_list`
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0