- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Removal of character # from a 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
Forums
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
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
тАО04-26-2011 03:28 PM
тАО04-26-2011 03:28 PM
I have a file which contains some data as below:-
pwd ##
date #
uptime ###
ls -lrt ##
time ##
How to see content of the file with cat command without # Character from each line ?
Thanks,
Manoj
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2011 03:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 04:38 PM
тАО04-27-2011 04:38 PM
Re: Removal of character # from a file
pwd ##pa;afsaf##
date #alsf'amsdf#
uptime ###afaf
ls -lrt ##asfsdf
time ##tab;ojd;afa
I want to see output as below:-
pwd
date
uptime
ls -lrt
time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 06:26 PM
тАО04-27-2011 06:26 PM
Re: Removal of character # from a file
Actually, it's often helpful to ask the
actual question whose answer you want, rather
than some other question whose answer is not
very useful to you. (Especially if you can't
adapt the useless answer to provide the
desired answer.)
> man sed
Still might be useful.
> [...] I don't want to see characters after
> # sign.
sed -e 's/#.*//' < a_file
s = substitute
#.* = "#", followed by one or more of any characters.
So, 's/#.*//' substitutes nothing for (the
first) "#", followed by one or more of any
characters.
Did I remember to suggest "man sed"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 08:23 PM
тАО04-27-2011 08:23 PM
Re: Removal of character # from a file
And see also regexp(5) where it discusses Regular Expressions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2011 08:57 PM
тАО04-27-2011 08:57 PM
Re: Removal of character # from a file
Of course, if you get to the bottom of the
"man sed" results, then that's already taken
care of, right?
[...]
SEE ALSO
awk(1), ed(1), grep(1), environ(5), lang(5), regexp(5), standards(5).
sed: A Non-Interactive Streaming Editor tutorial in the Text
Processing Users Guide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2011 01:06 AM
тАО04-28-2011 01:06 AM
Re: Removal of character # from a file
cat FILE_NAME | awk -F# '{ print $1 }'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-28-2011 04:13 AM
тАО04-28-2011 04:13 AM
Re: Removal of character # from a file
> cat FILE_NAME | awk -F# '{ print $1 }'
While I like this as yet another way to meet the goal, the use of the 'cat' process to read an input file and open a pipe for 'awk' to read that, is wasteful.
Simply do:
# awk -F# '{ print $1 }' FILE_NAME
...which is why Steven originally wrote, "If you insist" when he used 'cat'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2011 05:00 AM
тАО05-12-2011 05:00 AM
Re: Removal of character # from a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2011 07:37 AM
тАО06-06-2011 07:37 AM
Re: Removal of character # from a file
sed 's/#.*//;/^[ ]*$/d'
to display a script or config file without comments. (also removed blank lines)
For the same thing in awk, you can also use:
awk 'BEGIN{FS="#"}$1{print $1}'
Note: these methods will also cut code lines if "#" char is inside a quoted string, so they are not 'safe' for stripping comments from script/program code.
For your purpose, sed 's/#.*//' will work.