GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ignoring null values while greping
Operating System - HP-UX
1847068
Members
5332
Online
110261
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
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
03-18-2008 03:49 AM
03-18-2008 03:49 AM
Hi,
I have one file say:
myfile.txt, entries are:
"1234","0001"
"1235"," "
"1236"," "
"1237","0002"
I have writen code:
while read line
do
deep_cd= "NULL"
deep_cd=`grep "$deep_code" myfile.txt | cut -f2 -d','`
if [ deep_cd = null value ] then
deep_cd=NULL
else
echo " Value of deep_cd is $deep_cd "
fi;
echo "$deep_cd" >> diw_output
done
Output file will be something like:
my_output:
"0001"
NULL
"0002"
Can some one please help me in this regard.
Thanks
I have one file say:
myfile.txt, entries are:
"1234","0001"
"1235"," "
"1236"," "
"1237","0002"
I have writen code:
while read line
do
deep_cd= "NULL"
deep_cd=`grep "$deep_code" myfile.txt | cut -f2 -d','`
if [ deep_cd = null value ] then
deep_cd=NULL
else
echo " Value of deep_cd is $deep_cd "
fi;
echo "$deep_cd" >> diw_output
done
Output file will be something like:
my_output:
"0001"
NULL
"0002"
Can some one please help me in this regard.
Thanks
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2008 05:22 AM
03-18-2008 05:22 AM
Re: ignoring null values while greping
You can test for "definedness" (rather zero length string values) in the shell by
e.g.
[[ -z $deep_cd ]] && deep_cd=NULL
Does this help?
e.g.
[[ -z $deep_cd ]] && deep_cd=NULL
Does this help?
Madness, thy name is system administration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2008 05:42 AM
03-18-2008 05:42 AM
Solution
Hi:
This would yield your desired output using the input you showed:
#!/usr/bin/sh
IFS=","
while read A B
do
if [ "${B}" = '""' -o "${B}" = '" "' -o -z "${B}" ]; then
echo "NULL"
else
echo ${B}
fi
done < ./myfile.txt
...please cut-and-paste since the Forum will make this difficult to read...
Regards!
...JRF...
This would yield your desired output using the input you showed:
#!/usr/bin/sh
IFS=","
while read A B
do
if [ "${B}" = '""' -o "${B}" = '" "' -o -z "${B}" ]; then
echo "NULL"
else
echo ${B}
fi
done < ./myfile.txt
...please cut-and-paste since the Forum will make this difficult to read...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2008 01:09 AM
03-19-2008 01:09 AM
Re: ignoring null values while greping
Hi All,
Appologies for late reply.
Thanks a lot i got answer of my query.
Thanks
Appologies for late reply.
Thanks a lot i got answer of my query.
Thanks
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 2026 Hewlett Packard Enterprise Development LP