sed - specific line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - specific line
# 1  
Old 05-22-2015
Lightbulb sed - specific line

Hi all !
Please see if you can help me. I've used sed comand (with success) to remove content from the file when some word is found. Example:

Into to the file (FILE.txt) I've:
Code:
/folder1/folder2/folder3/XYZ
/folder1/folder2/folder3/ABC
/folder1/folder2/folder3/ZZZ

So I search by ZZZ (zzz is my folder name) for example and I can exclude entire line with success.
Example:
Code:
sed --in-place '/'$folder'/d' FILE.txt


The problem now is when inside the FILE.txt I've similar paths. Example:
Code:
/folder1/folder2/folder3/ZZZ
/folder1/folder2/folder3/ZZZ_bb

How can I exclude just /folder1/folder2/folder3/ZZZ?
*The path /folder1/folder2/folder3/ZZZ_bb should remain intact.

I've tried without success, because another problem that I found is because the line start with "/".

Example (it works because the line does not start with "/":
Code:
FILE.txt = 
folder1/folder2/folder3/test
folder1/folder2/folder3/test_xy
folder=folder1/folder2/folder3/test

sed "s|\<"$folder"\>||g" FILE.txt




Some suggestion?

Tks !

Last edited by Don Cragun; 05-22-2015 at 05:36 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 05-22-2015
Hi,

The first thing to point out is that when working with directory structures or dates don't use the forward slash as the separator change your statement to use something like;

Code:
sed --in-place ';$folder;d' FILE.txt

The next thing is please use code tags when inputing code.

Regards

Gull
# 3  
Old 05-22-2015
you want to end with ZZZ then use an anchor $

Code:
folder='/ZZZ$'
sed -i ";$folder;d"

# 4  
Old 05-22-2015
Hi neutronscott !

Not worked. See:

Code:
cat FILE.txt
/folder1/folder2/folder3/ZZZ
/folder1/folder2/folder3/ZZZ_xy

folder='/ZZZ$'
sed -i ";$folder;d"
sed: -e expression #1, char 8: unterminated address regex

sed -i ";$folder;d" FILE.txt
sed: -e expression #1, char 8: unterminated address regex


Last edited by Don Cragun; 05-22-2015 at 05:37 PM.. Reason: Add CODE tags.
# 5  
Old 05-23-2015
An address RE must be either /RE/ or \cREc
Code:
sed -i "\;$folder;d" FILE.txt

---------- Post updated 05-23-15 at 01:36 AM ---------- Previous update was 05-22-15 at 04:37 PM ----------

You can have as well
Code:
folder=ZZZ
sed -i '\;/'"$folder"'$;d' FILE.txt

This User Gave Thanks to MadeInGermany For This Post:
# 6  
Old 05-25-2015
Hi MadeInGermany !

Worked 100%

Tks !
# 7  
Old 05-26-2015
What about grep command ...??
in-placed replacemne won't happened here , you need to redirect outpt to temp file and then moved to original file.

Code:
 grep -vwE "ZZZ$" filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Adding a new line after a specific line with sed

Hi All, My requirement is to add a specific line in a file after a certain line that contains 'setenv' the existing code is like setenv SEQFILES "/ConvWrk/inteng03/alltars/bnymais1" LIBDEF scope='JOB' type='PGM' dataset='SUNAR.PJ90000P.JOBLIB'... (5 Replies)
Discussion started by: gotamp
5 Replies

2. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

sed to replace specific positions on line with file contents

Hi, I am trying to use an awk command to replace specific character positions on a line beginning with 80 with contents of another file. The line beginning with 80 in file1 is as follows: I want to replace the 000000000178800 (positions 34 - 49) on this file with the contents of... (2 Replies)
Discussion started by: nwalsh88
2 Replies

4. Shell Programming and Scripting

To add a new line with specific text after the pattern is found using sed

hi guys, im trying to add the following line in my xml file <dbrollbacksegs <oa_var="s_db_rollback_segs">NOROLLBACK</dbrollbacksegs> when ever i find the following line <dbsharedpool oa_var="s_dbsharedpool_size">300000000</dbsharedpool> I have succedded till adding a new line... (1 Reply)
Discussion started by: smarlaku
1 Replies

5. Shell Programming and Scripting

How delete characters of specific line with sed?

Hi, I have a text file with some lines like this: /MEDIA/DISK1/23568742.MOV /MEDIA/DISK1/87456321.AVI /MEDIA/DISK2/PART1/45753131.AVI /IMPORT/44452.WAV ... I want to remove the last 12 characters in each line that it ends "AVI". Should look like this: /MEDIA/DISK1/23568742.MOV... (12 Replies)
Discussion started by: inaki
12 Replies

6. Shell Programming and Scripting

sed to append on specific line in password file

I have the a group file and my ftp group line looks like this ... (3 Replies)
Discussion started by: slufoot80
3 Replies

7. Shell Programming and Scripting

sed / awk to get specific word in line

I have http log that I want to get words after specific "tag", this a sample line from the log: 98,POST,200 OK,www.facebook.com,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,/ajax/updatestatus.php?__a=1,datr=P_H1TgjTczCHxiGwdIF5tvpC; lu=Si1fMkcrU2SInpY8tk_7tAnw;... (6 Replies)
Discussion started by: erlanq
6 Replies

8. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

9. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

10. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies
Login or Register to Ask a Question