Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-03-2014, 05:05 AM   #1
LQ Newbie
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled
How can I read the specific position data in a file

Hello All,

Can you help me in writing a script for reading the specific position data in a file and if that data found in that file that particular file should be renamed.

Ex: Folder : C:\\test
and Filename : CLSACK_112214.txt,CLSACK_112314.txt,CLSACK_112414.txt
Contents in the file would be :
ISA* * * ~GS*CLS02*4010~ -> CLSACK_112214.txt
ISA* * * ~GS*CLS01*4010~ -> CLSACK_112314.txt
ISA* * * ~GS*CLS00*4010~ -> CLSACK_112414.txt

So first I need to read the first file CLSACK_112214.txt and in that I need to check conditions like

if the position from 15 to 21 == "*CLS02*"
then rename the current file(CLSACK_112214.txt) to UPDATEACK_112214.txt

Else if the position from 15 to 21 == "*CLS01*"
then rename the current file(CLSACK_112314.txt) to UPDATEACK_112314.txt

if the position from 15 to 21 == "*CLS01*"
then rename the current file(CLSACK_112414.txt) to UPDATEACK_112414.txt

So the script should read the files in the folder one by one and if any of the 3 conditions below gets satisfied then the current file should be reanme from CLSACK_XXXXXX.txt to UPDATEACK_112414.txt and then it should read next file and another file until the files in the folders scanning gets completed.

So anyone can give a script for the above scenario , it should be really help ful.

Old 12-03-2014, 01:32 PM   #2
LQ Addict
Registered: Dec 2013
Posts: 13,413
Blog Entries: 9

Rep: Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659Reputation: 3659
this: "C:\\test"
does not look like linux.

in what language do you want to script? bash?
there's a really good bash tutorial/wiki website here:
once you come up with something, show us what you tried, we might be able to assist.but we are not going to write that script for you.

Last edited by ondoho; 12-03-2014 at 01:35 PM.


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
parsing text file in C++ and read specific lines Alkass Linux - Newbie 4 12-16-2012 10:08 AM
[SOLVED] how to select date and some specific data from a log file shwhooda Linux - Newbie 2 06-25-2012 07:56 PM
read file and filter out specific tags in file noob_soni Linux - Newbie 2 12-11-2009 08:25 PM
Read specific lines from a text file chobin Programming 8 06-14-2006 12:14 PM
read file and analyze position j-me Linux - Newbie 3 07-18-2003 06:54 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:21 AM.

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