Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed Command Troubles

Status
Not open for further replies.

Nevets1106

Programmer
Aug 23, 2007
6
US
I have a file that contains a snapshot of all the current files and directories. I am trying to remove several directories from this snapshot. What I have is:

sed '/\/tmp/ d' snapshot


The issue is that the sed command uses the same delimeter as the directory /. I've tried setting the directory to a variable and using double quotes as below with no luck:

dir= "/tmp"
sed "/$dir/ d' snapshot

Any help or suggestions would be very appreciated. Thanks ahead of time
 
I think you can use ; (semi colon) as a delimiter too. Please try and let me know if it works
 
As suggested I tried both statements below. Neither has worked.

sed ';/tmp;d' snapshot
sed ':/tmp:d' snapshot
 
Hi

Honestly I do not understand what you want. Your first code is correct and works.
Code:
sed '/\/tmp/ d' snapshot
There is no other way in [tt]sed[/tt]. For example in [tt]perl[/tt] there are the [tt]m[/tt] and [tt]s[/tt] functions which can eliminate the ambiguity :
Code:
perl -pe '$_="" if m:/tmp:' snapshot
But while in [tt]sed[/tt] there is only [tt]s[/tt] and no m, you can use custom delimiters only in substituting and not in matching.

Feherke.
 
When I use the command below, I'm recieving "Can't open shanpshot" even though snapshot has -rwxrwxrwx- permissions.

sed '/\/tmp/ d' snapshot


I guess the sed command is being processed correctly, but what else could be causing "Can't open shanpshot" error?
 
By the way, I am working in a Sun Solaris Unix environment.
 
It just sounds like there is no file called 'snapshot' in the current directory. Have you checked?

Annihilannic.
 
perhaps your snapshot file has a (at least for ls output invisible) whitespace character in it at the end?

output of

Code:
ls *snap*|od -xc

please?


HTH,

p5wizard
 
Try using the full path to snapshot

sed '/\/tmp/ d' /home/user/username/snapshot



Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
I couldn't get this sed issue worked out however, I found a way to work around it. I learned of the grep -v option which acts as a reverse grep. I used this to remove unwanted directories as I was doing my snapshot comparison. So now I have code listed below. Thanks for everyones help.

Code:
#Create snapshot
du -h >> /usr/todaysnapshot.txt
diff -c todaysnapshot.txt previoussnapshot.txt | grep -v "/temp*" >> snapshotreport.txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top