HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: run script in sequence
Operating System - HP-UX
1837085
Members
2342
Online
110112
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2008 06:08 PM
01-21-2008 06:08 PM
I have a script to read the .txt file in /tmp , the script will read the file content then write something to the file ( write different thing to different file depend the file content )
cat /tmp/*.txt |grep .... ; do ...
suppose there should only have one .txt file in /tmp , it works fine if there is only one .txt file , but however , sometimes there are more than one .txt file in it , in this case the result is not correct ( becuase the script cat the content for all *.txt file by one time) , so I would like to ask is there any way that when run my script it first check the existence of *.txt files , to make sure the files are read in sequence ( so that they write the correct thing to file ) , that mean the script will process every file for one time only .
for example
if there is one .txt file in /tmp
$ls /tmp
aaa.txt
when run my_script
$my_script /tmp
then it run my_script aaa.txt , it works fine
But , if in case there are 3 .txt files in /tmp
$ls /tmp
bbb.txt
ccc.txt
ddd.txt
when run my_script
$my_script /tmp
it will cat bbb.txt ccc.bbb.txt ddd.txt to find some content , then write it to each file , so the result is not correct.
what I want is when run my_script
$my_script /tmp
it run my_script bbb.txt , my_script ccc.txt & my_script ddd.txt separately,
can advise what can i do ? thx
cat /tmp/*.txt |grep .... ; do ...
suppose there should only have one .txt file in /tmp , it works fine if there is only one .txt file , but however , sometimes there are more than one .txt file in it , in this case the result is not correct ( becuase the script cat the content for all *.txt file by one time) , so I would like to ask is there any way that when run my script it first check the existence of *.txt files , to make sure the files are read in sequence ( so that they write the correct thing to file ) , that mean the script will process every file for one time only .
for example
if there is one .txt file in /tmp
$ls /tmp
aaa.txt
when run my_script
$my_script /tmp
then it run my_script aaa.txt , it works fine
But , if in case there are 3 .txt files in /tmp
$ls /tmp
bbb.txt
ccc.txt
ddd.txt
when run my_script
$my_script /tmp
it will cat bbb.txt ccc.bbb.txt ddd.txt to find some content , then write it to each file , so the result is not correct.
what I want is when run my_script
$my_script /tmp
it run my_script bbb.txt , my_script ccc.txt & my_script ddd.txt separately,
can advise what can i do ? thx
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2008 06:24 PM
01-21-2008 06:24 PM
Solution
>cat /tmp/*.txt |grep .... ; do ...
You do know that grep can take a list of files. And depending on whether you want the name of the file in the output, you can either use cat(1) or use grep -h to suppress.
>sometimes there are more than one .txt file in it, in this case the result is not correct (because the script cat the content for all *.txt file by one time)
You need to explain why it isn't correct or provide more of your script fragment.
>to make sure the files are read in sequence (so that they write the correct thing to file ),
Sequence is alphabetically. What is the correct thing to write?
>that mean the script will process every file for one time only.
You can also do that with a "for" loop.
>what I want is when run my_script
$ my_script /tmp
If you want to process each file separately you can do:
for file in $1/*.txt; do
grep ... $file ...
done
You do know that grep can take a list of files. And depending on whether you want the name of the file in the output, you can either use cat(1) or use grep -h to suppress.
>sometimes there are more than one .txt file in it, in this case the result is not correct (because the script cat the content for all *.txt file by one time)
You need to explain why it isn't correct or provide more of your script fragment.
>to make sure the files are read in sequence (so that they write the correct thing to file ),
Sequence is alphabetically. What is the correct thing to write?
>that mean the script will process every file for one time only.
You can also do that with a "for" loop.
>what I want is when run my_script
$ my_script /tmp
If you want to process each file separately you can do:
for file in $1/*.txt; do
grep ... $file ...
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2008 12:02 AM
01-22-2008 12:02 AM
Re: run script in sequence
Thx
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP