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, 11:36 AM   #1
conejo_perez16
LQ Newbie
 
Registered: Aug 2012
Posts: 11

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, 12:11 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,309

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

Original Poster
Rep: Reputation: Disabled
Honestly I haven't even tried, but no good ideas come to my mind
 
Old 08-18-2012, 06:33 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,309

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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05: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
Open Source Consulting | Domain Registration