simple file edit

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers simple file edit
# 1  
Old 11-19-2001
simple file edit

What command can I use to simply edit a file by searching for a word and then deleting the lines that I find that word in?
# 2  
Old 11-19-2001
I would recommend using vi. For example, a file named text.txt you would "vi text.txt" You would use a "/" and then type the string you are searchin gfor and it would go to that line. You could use dd the delete the entire line. I would recommend doing a man on vi as it is confusing at first.
# 3  
Old 11-19-2001
I know I can do it in an editor like vi but I'm wondering how I can do it using a command like sed or something similar.
# 4  
Old 11-19-2001
You probably want to use sed for this. Try something like the following:

sed '/MYSTRING/d' myfile > myfile2.out
# 5  
Old 11-20-2001
use grep


You can also use grep.

cat file1 |grep -v string > file2

The "-v" option for grep will omit any lines that contain the string.

Also, you can use this to delete blank lines from a file as follows.

cat file1 |grep -v ^$ > file2

In my opinion, "grep" is a very powerful tool along with the "find" command. They are 2 very good tools in UNIX.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Edit file

Hi All, I have file with 200K Records and each line with 400 character. I need to edit the some part of the file. For example, i need to edit character from 115 to 125, 135to 145 and 344 to 361 Can you please anyone help me to do this? Regards, (1 Reply)
Discussion started by: balasubramani04
1 Replies

2. Shell Programming and Scripting

Script to make simple recurring ascii file edit

Hi, I have an ascii file with recurring lines (the file is 36mb so lots of lines) which look like this: -2.5 -66.324-68.138 935.2 1.953 -0.664 272.617 73.684 -2.428 269.998 0.000 Every 14 lines there is a blank line. I would like to, for each non-blank line,... (2 Replies)
Discussion started by: blueade7
2 Replies

3. Shell Programming and Scripting

edit file

I have a file containing dates like below 2010 1 02 2010 2 01 2010 3 05 i want the dates to be like below 20100102 20100201 20100305 i tired using awk '{printf "%s%02s%02s",$1,$2,$3}' But it does not work,it puts all the dates in one line,i want them in seperate lines like the... (6 Replies)
Discussion started by: tomjones
6 Replies

4. Shell Programming and Scripting

Edit a file

I have file like cp -p /var/adm/ /tmp1/tmp1.log cp -p /var/adm/ /tmp1/tmp2.log cp -p /var/adm/ /tmp1/tmp3.log cp -p /var/adm/ /tmp1/tmp4.log I need to re-write the file like: cp -p /var/adm/tmp1.log /tmp1/ cp -p /var/adm/tmp2.log /tmp1/ cp -p /var/adm/tmp3.log /tmp1/ cp -p... (3 Replies)
Discussion started by: h_banka
3 Replies

5. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

6. Shell Programming and Scripting

Help edit simple payroll script?

I'm trying to write a simple script to figure pay with overtime...I got the first part to work, but I can't seem to get the second if statement's syntax right...:confused:I want it to take the 40 hours times 10 dollars, but then i want whatever is left over (like 7 of 47 hours) and take that times... (6 Replies)
Discussion started by: miss72006
6 Replies

7. Shell Programming and Scripting

Edit value in File

I have a file oratab with entry like this SCADAG:/esitst1/oracle/product/ I am trying to discover a way to change the part of this to something like as part of an upgrade script. I have tried cat /etc/oratab >>/tmp/oratab... (1 Reply)
Discussion started by: sewood
1 Replies

8. UNIX for Dummies Questions & Answers

edit a .fs file

I have a .fs file that I want to edit, (or just be able to see what is in it) preferably through a windows environment. Does anyone know how to do that? Thanks (4 Replies)
Discussion started by: kiterboy
4 Replies

9. Shell Programming and Scripting

Simple SED edit

I have output like the following: B D 20070116095820001 N D S0000579.LOG S0000582.LOG B D 20070116095750001 N D S0000574.LOG S0000576.LOG B D 20070116095734001 N D S0000570.LOG S0000573.LOG B D 20070116095705001 N D S0000569.LOG S0000569.LOG B D ... (5 Replies)
Discussion started by: rdudejr
5 Replies

10. Shell Programming and Scripting

file edit help

Hi, Could anyone give me a idea how to strip the lines from a given file. example *********** 1st occurence 1st occurence 1st occurence 1st occurence *********** 2nd occurence 2nd occurence 2nd occurence 2nd occurence 2nd occurence 2nd occurence ************* 3rd occurence 3rd... (10 Replies)
Discussion started by: sentak
10 Replies
Login or Register to Ask a Question