- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Deleting file lines in shell script
Operating System - HP-UX
1753964
Members
7106
Online
108811
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
Discussions
Discussions
Forums
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
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
тАО06-23-2000 07:44 AM
тАО06-23-2000 07:44 AM
Deleting file lines in shell script
Is there a way to delete a line in a file if you are reading from file1 and you want to delete line from file2 matching certain critera? I'm trying to use standard UNIX commands to accomplish.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2000 08:03 AM
тАО06-23-2000 08:03 AM
Re: Deleting file lines in shell script
The sed command is probably what you want, but the syntax can be tricky. The man page helps, but you might want to pick up some additional references. (O'reilly is always a good place to start.)
If you post more details about your specific problem, I might be able to give you a more complete response.
If you post more details about your specific problem, I might be able to give you a more complete response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-23-2000 08:06 AM
тАО06-23-2000 08:06 AM
Re: Deleting file lines in shell script
The use of 'sed' will accomplish your goal.
The question of "certain criteria" needs to be established. Once done, you could invoke sed. Example to delete blank lines with a file: sed -e /^$/d
Another option to delete lines: sed -e /$pattern/,^$/d file > newfile
This will delete the line matching the pattern up to the first blank line.
The question of "certain criteria" needs to be established. Once done, you could invoke sed. Example to delete blank lines with a file: sed -e /^$/d
Another option to delete lines: sed -e /$pattern/,^$/d file > newfile
This will delete the line matching the pattern up to the first blank line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-26-2000 11:16 AM
тАО06-26-2000 11:16 AM
Re: Deleting file lines in shell script
If what you are trying to do is delete lines from two files that are the same in each file try this, i made this when trying to do the same thing
This only works if each line is one string with no spaces
cat file1 file2 >> tempfile
sort tempfile > temp2file
rm tempfile
uniq -d temp2file > temp3file
rm temp2file
(this will be a list of all line the same in both files)
(now to delete those lines)
for X in `cat temp3file`
do
grep -v ^$X$ file1 > temp4file
cp temp4file file1
grep -v ^$X$ file2 > temp4file
cp temp4file file2
sleep 1
done
then remember to delete temp3file and temp4file
i do all this in a script wich is much easier
but this is how i'd do it from the command line
This only works if each line is one string with no spaces
cat file1 file2 >> tempfile
sort tempfile > temp2file
rm tempfile
uniq -d temp2file > temp3file
rm temp2file
(this will be a list of all line the same in both files)
(now to delete those lines)
for X in `cat temp3file`
do
grep -v ^$X$ file1 > temp4file
cp temp4file file1
grep -v ^$X$ file2 > temp4file
cp temp4file file2
sleep 1
done
then remember to delete temp3file and temp4file
i do all this in a script wich is much easier
but this is how i'd do it from the command line
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP