How to remove a line from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove a line from a file
# 1  
Old 06-24-2010
Bug How to remove a line from a file

./xxibe
./xxibe/11.5.0
./xxibe/11.5.0/admin
./xxcyb/11.5.0/reports/US
./xxkintana
./xxkintana/1016454
./xxkintana/1016454/backup
./xxkintana/1016454/updates

./xxcpf/11.5.0/xml_gw
./xxcse
./xxcse/11.5.0
./xxcse/11.5.0/admin


I have a file (sample.txt) this file contains above text.
I need to remove (delete) the lines from the file which are in RED color means which are starts with ./xxk

Thanks in Advance.
Gagan

Last edited by gagan4599; 06-24-2010 at 05:55 AM.. Reason: modified content
# 2  
Old 06-24-2010
Try,

Code:
$ grep -v xxkintana sample.txt

# 3  
Old 06-24-2010
as said by agn the query will work perfectly for the given case.
if the pattern is similar then it will work definately...
# 4  
Old 06-24-2010
Quote:
Originally Posted by agn
Try,

Code:
$ grep -v xxkintana sample.txt



Hai Agn,

the above command deleting lines and showing output at $ prompt, but when i opened the sample.txt file the lines are still there only.
I need to Remove the lines from the file and save.

Thanks in Advance
# 5  
Old 06-24-2010
Code:
cut -f1 -d `grep -v xxkitana sample.txt` >> output_file

try this. i havent checked it yet but something like this shud work

---------- Post updated at 04:12 AM ---------- Previous update was at 04:09 AM ----------

sorry this will not work dnt try...... let me try awk.. wait a sec

---------- Post updated at 04:16 AM ---------- Previous update was at 04:12 AM ----------

Code:
 
awk -v f=0 '/xxkintana/ {f=0} /xxkintana/1016454/updates/{f=1} { print > "file_"f }' input_file

try this it shud work.....
# 6  
Old 06-24-2010
Code:
cat sample.txt | grep -v '^./xxk' >> result.txt

# 7  
Old 06-24-2010
GNU sed,

Code:
sed -i '/xxkintana/d' sample.txt

starting with ./xxk

Code:
sed -i '/^\.\/xxk/d' sample.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove first line of file

How can I use bash to remove the first line of a file? (3 Replies)
Discussion started by: locoroco
3 Replies

2. Shell Programming and Scripting

Remove line from file and read file line by line

I have a file output.txt. File looks like this name1 10 name2 2 name3 5 I get a number n and I need to remove all lines which has number (after name) smaller or equal to n number. After that I need to write lines from file and my output must be like this: Output: 'name1 10' Output: 'name2... (1 Reply)
Discussion started by: kubo12312
1 Replies

3. Shell Programming and Scripting

How to remove last line of the file

Hi, unix gurus, I need to remove last line of the file. anybody can help me thanks in advance (7 Replies)
Discussion started by: ken002
7 Replies

4. Shell Programming and Scripting

Remove first line of file

Is there an easy way to remove the first line of a file so that the file: aaron benjamin cecilia daniel elliot fernando would become benjamin cecilia daniel elliot fernando (4 Replies)
Discussion started by: locoroco
4 Replies

5. Shell Programming and Scripting

Remove a line from a file

Hi ,guys. I have one question: I want to write a script which removes a line with certain string from a file, for example The name of the file is: "passwd", the contents of it is below: ************************* ... brownj2:x:5000: hynesp:x:5001: leeb:x:5002 dioxna:x:5003 ... ... (2 Replies)
Discussion started by: daikeyang
2 Replies

6. UNIX for Dummies Questions & Answers

remove a line within a file

Hi all, i have a text file similar to belowA1 A2 A3 B1 ... .... *** # first occurance B1 ... .... *** # second occurance B1 ... .... *** # third occurance My desired output is B1 ... .... *** # second occurance B1 ... .... *** # third occurance I want to remove the first line that is after... (3 Replies)
Discussion started by: new2ss
3 Replies

7. Shell Programming and Scripting

How to remove last line of the file

hi sir, i need help..how to remove last line of the each file for example i have files a.txt ,b.txt and so on..i wanted to delete last list of each file..the patten not same for each file..any help? thanks in advance (3 Replies)
Discussion started by: mani_um
3 Replies

8. Shell Programming and Scripting

Remove header(first line) and trailer(last line) in ANY given file

Hi, I need some help in removing the header (first line) and the trailer (last line) in a give file... The data file actually comes in EBCDIC format and I converted it into ASCII.. Now I need to strip off the first line and the last line.. I think we can use sed to do something like this:... (2 Replies)
Discussion started by: madhunk
2 Replies

9. Shell Programming and Scripting

Remove every third line from a file

I need to remove every second and every third line from a file. My idea was to do it in two operations. First every third line, then every second line. The problem is that i can't find out how to do it. I tried to look for some sed oneliners, but couldn't find any. Suggestions? (4 Replies)
Discussion started by: bistru
4 Replies
Login or Register to Ask a Question