- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Quick commands to ignore comments in text file.
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
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
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-09-2002 12:06 AM
тАО07-09-2002 12:06 AM
Are there any quick commands to ignore comments in a text/script files? Meaning I wish to ignore all the characters and words after the character "#" in the file.
Siew Hoong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 12:12 AM
тАО07-09-2002 12:12 AM
Re: Quick commands to ignore comments in text file.
If you are using vi, then at the ":" prompt type 1,$ s/#.*//g
then it will substitute all the characters beginning "#" with null.
Regards,
Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 12:17 AM
тАО07-09-2002 12:17 AM
Re: Quick commands to ignore comments in text file.
cat file.txt|grep -v "^#"
regards seba
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 12:54 AM
тАО07-09-2002 12:54 AM
Re: Quick commands to ignore comments in text file.
And grep -v "^#" also does not work because if there are words before the "#" character, the whole line would be included
ex
#Comments <- this works
Some texts #Some comments <- this does not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 01:00 AM
тАО07-09-2002 01:00 AM
Re: Quick commands to ignore comments in text file.
You can write a script name a.ksh with the following content,
---begin---
#!/bin/ksh
if [ $# -ne 1 ]
then
echo
echo "Usage : `basename $0`
echo
exit 0
fi
cat - << EOF | ed -s $1
1,$ s/#.*//g
w
q
EOF
---end---
Then at command prompt, type
ksh a.ksh file.txt
and you will have the file.txt changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 01:17 AM
тАО07-09-2002 01:17 AM
Re: Quick commands to ignore comments in text file.
sed alone will do the trick:
cat my_file | sed -e 's/#.*//g'
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 01:19 AM
тАО07-09-2002 01:19 AM
Re: Quick commands to ignore comments in text file.
I forgot to save on the cat and pipe:
# sed -e 's/#.*//g' my_file
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 02:05 AM
тАО07-09-2002 02:05 AM
Solution# sed -e 's/#.*//g' -e '/^$/d' my_file
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-09-2002 02:58 AM
тАО07-09-2002 02:58 AM
Re: Quick commands to ignore comments in text file.
cheers
Siew Hoong