Results 1 to 9 of 9
I am trying to find a way in bash to delete all lines in a file that contains the backslash (\) . I tried using sed to delete the file ...
- 11-02-2007 #1Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Delete lines that match.
I am trying to find a way in bash to delete all lines in a file that contains the backslash (\) . I tried using sed to delete the file out with the \\ to delete the lines but this does not appear to work.
I am going to be making a script that will read a file full of these lines. I figured sed would be the easy one to do this.Code:sed /"ACC7575 NAS\Backup of files on X$,System State and Services Database\bob"/d
- 11-02-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try:
RegardsCode:grep -v '\\' file
- 11-02-2007 #3Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
If you prefer sed:
RegardsCode:sed '/\\/d' file
- 11-02-2007 #4Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
Let me clarify what I meant
Status:
I have those lines in a file.Code:ACCT00251 SERVER01\Backup of files on P$\administrator Thursday ACCT00251 DC\Backup of System State \administrator Thursday ACCT00251 SUA\Backup of files on D$\administrator Thursday ACCT00253 BOB1\Backup of files on C$,D$\admin Thursday ACCT00253 MIKE\Backup of Microsoft Exchange Server\admin Thursday ACCT00253 RCLS03\Backup of files on C$,D$\admin Thursday
In another file I have a few lines that look like:
Exclusion:
I want to delete any line in in the exclusion file that matches in the status file. I was trying to make sed delete the lines (I want to match the full line aside from the Day (in the example Thursday). But I was unable to get sed to delete anything because the file has \ and if I add \\ to the exlcude file it will still not delete the file.Code:ACCT00253 MIKE\Backup of Microsoft Exchange Server\backup_admin ACCT00253 BOB1\Backup of files on C$,D$\admin
- 11-02-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
- 11-03-2007 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:awk 'BEGIN{ FS="\\" } NR==FNR{ a[$1$2]=$0;next} { if ( !( $1$2 in a ) ) print $1 } END { }' "statusfile" "exclusion"
- 11-03-2007 #7Just Joined!
- Join Date
- Oct 2007
- Location
- Houston
- Posts
- 75
If the line exists in the exclusion file delete that line from the status file. I had a phone call while typing that post up. Sorry. I switched the exclusion and status file but it is not deleting right. I need the line to be an exact match to ensure we do not delete a similar line.
- 11-03-2007 #8Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
You can simply change the order of the 2 files like this:
An exact match of the whole line in both files:Code:awk 'NR==FNR{x[$1$2];next}$1$2 in x{next}1' Exclusionfile Statusfile
RegardsCode:awk 'NR==FNR{x[$0];next}$0 in x{next}1' Exclusionfile Statusfile
- 11-04-2007 #9Linux User
- Join Date
- Aug 2006
- Posts
- 458


Reply With Quote
