- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- deleting something 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
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
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-05-2005 11:57 AM
07-05-2005 11:57 AM
.
..
test
ile01
file02
file03
i want to delete the . and .. so that the content of the file looks like
test
ile01
file02
file03
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 01:39 PM
07-05-2005 01:39 PM
Re: deleting something from a file
You can open the file using vi editior and delete the first 2 line and save it. then the file will have the required line.
or use sed or awk to print line from 3 till the end to another file.
eg:-
sed -n -e 3,6p fil01 > tempfile
This will take lines from 3 to 6 (if the number of line in the file are 6) and tempfile will have lines excluding . and ..
IA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 03:55 PM
07-05-2005 03:55 PM
Solution# cat file01 | grep -v -e '^[ ]*\.[ ]*$' -e '^[ ]*\.\.[ ]*$' > file02
"file02" will have what you want.
Note that the above solution will handle
corner cases like:
1) when a file name itself has . or .. char
2) . and .. files names are not at the
beginning of line and might prepended or
appended with blank spaces.
Hope this helps.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 05:38 PM
07-05-2005 05:38 PM
Re: deleting something from a file
grep -v '^\.' file01 > file02
mv file02 file01
or
perl -i -ne '$_=~s/^\.*//;print if !/^$/' file01
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 05:48 PM
07-05-2005 05:48 PM
Re: deleting something from a file
sed -e '/\.$/d' file_name > new_file
It will be a general case or a precise one will be deleting the 1st and 2nd lines
sed -e 1,2d file_name > new_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 06:54 PM
07-05-2005 06:54 PM
Re: deleting something from a file
Solution of,
# cat file01 | grep -v -e '^[ ]*\.[ ]*$' -e '^[ ]*\.\.[ ]*$' > file02
is having few issues as,
1) cat file01 |
grep -v -e '^[ ]*\.[ ]*$' -e '^[ ]*\.\.[ ]*$' < file01 > file02
2) Why you are checking spaces after . or .. ? It may be very simple as,
grep -v '^[ ]*\.*[ ]*$' < file01 > file02
3) This operation will need temporary file. You can use perl -i to update into same file as,
perl -i -ne '$_=~s/^[ ]*\.*[ ]*$//;print if !/^$/'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 09:53 PM
07-05-2005 09:53 PM
Re: deleting something from a file
> 2) Why you are checking spaces after . or ..
> ? It may be very simple as,
>
> grep -v '^[ ]*\.*[ ]*$' < file01 > file02
That would match '...' too, which would be
incorrect.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 10:24 PM
07-05-2005 10:24 PM
Re: deleting something from a file
It will match for ... also. Check out as,
# echo '...' | grep '^[ ]*\.*[ ]*$'
Where,
^ - starting point
[ ]* - 0 or n spaces
\.* - . (dot) with zero or n times (if you want 1 or more times then use + instead of *)
[ ]* - 0 or n spaces
$ - end point
# echo "..." | grep -v '^[ ]*\.*[ ]*$'
#
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2005 10:28 PM
07-05-2005 10:28 PM
Re: deleting something from a file
grep -Ev '^[ ]*\.[ ]*$|^[ ]*\.\.[ ]*$'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2005 12:07 AM
07-06-2005 12:07 AM
Re: deleting something from a file
Using '|' to separate two search strings (like
your previous reply) is essentially same
(performance wise) as using '-e' option twice
(as my first reply), AFAIK.
- Biswajit