LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2005, 10:43 PM   #1
izza_azhar
LQ Newbie
 
Registered: Jan 2005
Location: malaysia
Posts: 18

Rep: Reputation: 0
split string prob


my old program is using cut to get the date of the file such:
for FILE in ATK*
do
file_year=$(echo $FILE| cut -c 13-16)
file_month=$(echo $FILE|cut -c 13-18)
###
echo $file_month --->just as example!
done
where filename is such:
ATK_7B1_WIP_20041116160700.1.xml.dsc
ATK_7B1_WIP_20041116160700.2.xml.dsc
ATK_7B1_WIP_20041116160700.3.xml.dsc
ATK_7B1_WIP_20041116160700.4.xml.dsc

problem is how can i enhance it to all filename?
such:
AIT_7B1_WIP_20050101010101.dsc
ASECL_7B1_WIP_20041209151027.xml.dsc
ASEKR_7B1_WIP_20050101020202.dsc

so i cant use the ' for FILE in ATK* ' rite?
should replace with what?
all the filename will be the same unless the front name:
xxxx_7B1_WIP_20041116160700xxx
help!!!
 
Old 02-07-2005, 11:03 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,565

Rep: Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425
echo $FILE|cut -d'_' -f4|cut -c 1-4
gives year. For mth change last item to 5-6.
 
Old 02-07-2005, 11:34 PM   #3
izza_azhar
LQ Newbie
 
Registered: Jan 2005
Location: malaysia
Posts: 18

Original Poster
Rep: Reputation: 0
ok thanks..it..really work..bout how bout to list that?
'for FILE in ATK*'
it must be replace with smothing rite?
coz not all the filename start with ATK_xxx..
 
Old 02-08-2005, 01:11 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,565

Rep: Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425
Keep only the files you need to process in the work dir;
cd <your data file dir>
for FILE in `ls -1`
ie keep program out of data file dir.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split a string on newlines (bash) rose_bud4201 Programming 7 04-14-2005 02:58 PM
split string izza_azhar Programming 6 01-18-2005 09:24 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 02:39 PM
Need to split an input string general4172 Linux - Software 6 10-30-2003 12:57 AM
perl string split problem! farhanali Programming 4 06-22-2003 08:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration