LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-18-2012, 12:36 PM   #1
conejo_perez16
LQ Newbie
 
Registered: Aug 2012
Posts: 10

Rep: Reputation: Disabled
Bash Scripting, looping through subdirectories to create 1 and 0 column of values


Hello, everybody, I have several subdirectories which contains several files with .SAC extension, for example

folder01
01.SAC
02.SAC
04.SAC

Notice 03.SAC is missing.

folder 02
02.SAC
03.SAC
04.SAC

Notice 01.SAC is missing

So, what I need is.. for every missing file display a 0, otherwise display 1

For example

from folder01 I need a simple text file (lets say file01.dat)with a column with the following:

1
1
0
1

Similarly for folder02 I need (file02.dat)

0
1
1
1

And if possible merge all this, like:

finalfile.dat

1
1
0
1
0
1
1
1

Is there a way to do this????

Thanks!!
 
Old 08-18-2012, 01:11 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,026

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
where in your script are you having problems ?
 
Old 08-18-2012, 04:40 PM   #3
conejo_perez16
LQ Newbie
 
Registered: Aug 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Honestly I haven't even tried, but no good ideas come to my mind
 
Old 08-18-2012, 07:33 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,026

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
use the find command in a loop looking for 01.sac, 02.sac, 03.sac, ...
if the string that find returns is not zero length then echo '1'; else echo '0'.

man find
man test
 
  


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
BASH scripting: check for numeric values linuxLuser Programming 11 11-14-2011 11:11 AM
need help in bash scripting...need to arrange variables in column wise manya Programming 7 11-07-2009 02:54 AM
bash best practice : scripting actions to be done in all current subdirectories billywayne Programming 4 08-01-2009 08:42 PM
Looping issue in bash scripting ZAMO Linux - General 4 09-26-2008 12:22 PM
Bash Scripting (subdirectories) bendeco13 Linux - General 4 10-07-2004 01:24 AM


All times are GMT -5. The time now is 08:33 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