- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script - For and IF issue
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
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
Community
Resources
Forums
Blogs
- 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
07-12-2012 02:57 PM
07-12-2012 02:57 PM
Hello experts..
I'm trying to copy a file the same way that it is, but when it find a NULL character, must input another value.
eg (what I need).
File1.txt
80
80
80
File2.txt
80
100
80
80
Whats going on
Scipt:
for i in File1.txt ;
do
if [ `cat File1.txt` == "" ]
then
echo "100" >> File2.txt
else
cat File1.txt >> File2.txt
fi
done
# cat File1.txt
80
80
80
# sh -x test.ksh
+ cat File1.txt
+ [ 80 80 80 == ]
test.ksh[5]: 80: 0403-012 A test command parameter is not valid.
+ cat File1.txt
+ 1>> File2.txt
#cat File2.txt
80
80
80
Could some help me please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2012 04:13 PM - edited 07-12-2012 08:43 PM
07-12-2012 04:13 PM - edited 07-12-2012 08:43 PM
SolutionIf you want to read File1.txt and copy all but empty lines to File2.txt, then you need to use a while vs for loop:
while read line; do
if [ "$line" = "" ]; then # Note only one "="
echo "100"
else
echo "$line"
fi
done < File1.txt > File2.txt
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2012 08:10 PM
07-12-2012 08:10 PM
Re: Shell Script - For and IF issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2012 07:31 AM
07-13-2012 07:31 AM
Re: Shell Script - For and IF issue
it worked!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2012 04:10 PM
07-13-2012 04:10 PM
Re: Shell Script - For and IF issue
>Thanks Dennis and Steven!!
If you are happy with your answers, please click on the Kudos stars of the helpful posts.