Deleting of Specific Rows.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting of Specific Rows.
# 1  
Old 01-10-2010
Deleting of Specific Rows.

Fruit : Price : Quantity
apple : 20 : 40
chiku : 40 :30

Hey guys, i have written a code using sed to delete a specific char which is being typed in. But the problem i am having is , how can i expand my coding to actually allow it do delete the whole row. For example, if i type in apple, i would like it to delete the other information about apple such as price and quantity.


Code:
Title=
echo -n "Title "
read Title
  
cat database | \

sed -e '/ "$Title" /d' > database

Can sombody help me in giving me a headstart on how i am able to expand this coding to include it to delete the entire row?
# 2  
Old 01-10-2010
One way to do this would be to write all lines except the ones containing $Title to a temp file, then rename the temp file to the original. You can do this using "grep -v":

Code:
grep -v "$Title" database > database.tmp
mv database.tmp database

# 3  
Old 01-10-2010
it did work. but the issue is , that it only deletes the "$Title" and not the entire row. I tried something out.

Code:
Title=
echo -n "Title:"
read Title  
#cat fruit | \
#sed -e '/apple/d' > fruit

grep -v "$Title , $2  , $3" fruit > fruit_temp
mv fruit_temp fruit

i tried to get it to read the 2 and 3 words but it does not seem to work. can sombody explain to me why?
# 4  
Old 01-10-2010
Since your file is delimited by ":", then change your grep statement to:

Code:
grep -v "$Title : $2 : $3" fruit > fruit_temp

# 5  
Old 01-10-2010
Nothing seemed to have happened. Am i writing the statements correctly?
# 6  
Old 01-10-2010
Quote:
Originally Posted by gregarion
Fruit : Price : Quantity
apple : 20 : 40
chiku : 40 :30

Hey guys, i have written a code using sed to delete a specific char which is being typed in. But the problem i am having is , how can i expand my coding to actually allow it do delete the whole row. For example, if i type in apple, i would like it to delete the other information about apple such as price and quantity.


Code:
Title=
echo -n "Title "
read Title
  
cat database | \

sed -e '/ "$Title" /d' > database

Can sombody help me in giving me a headstart on how i am able to expand this coding to include it to delete the entire row?
Can you show us code you used to delete specific char?
# 7  
Old 01-10-2010
okay, i used

T
Code:
itle=
echo -n "Title:"
read Title  
#grep -v "$Title" fruit > fruittemp
#mv fruittemp fruit

Actually this can be used to solve my problem because it does delete all the information in that row. but can sombody explain to why must be send the output to a new file and then rename it? cant we just send the output to the same file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Deleting rows where the value in a specific column match

Hi, I have a tab delimited text file where I want to delete all rows that have the same string for column 1. How do I go about doing that? Thanks! Example Input: aa 1 aa 2 aa 3 bb 4 bc 5 bb 6 cd 8 Output: bc 5 cd 8 (4 Replies)
Discussion started by: evelibertine
4 Replies

2. Shell Programming and Scripting

deleting rows under a certain condition

there are 20 variables and I would like to delete the rows if 13th-20th columns are all NA. Thank you! FID IID aspirpre statihos fibrahos ocholhos arbhos betabhos alphbhos cacbhos diurehos numbcig.x toast1 toast2 toast3 toast4 ischoth1 ischoth2 ischoth3 ischoth4 101 101 1 1 1 1 1 2 1 2... (2 Replies)
Discussion started by: johnkim0806
2 Replies

3. UNIX for Dummies Questions & Answers

Deleting specific rows from a text file

How do I go about deleting specific rows from a text file (given row number)? (5 Replies)
Discussion started by: evelibertine
5 Replies

4. UNIX for Dummies Questions & Answers

Help with deleting specific rows from a text file

I know this is a complicated question but I will try to illustrate it with some data. I have a data file that looks like the following: 1341 NA06985 0 0 2 46.6432798439 1341 NA06991 NA06993 NA06985 2 48.8478948517 1341 NA06993 0 0 1 45.8022601455 1340 NA06994 0 0 1 48.780669145 1340... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

deleting rows that have certain characters

Hi, I want to delete rows whenever column one has the letters 'rpa'. The file is tab seperated. e.g. years 1 bears 1 cats 2 rpat 3 rpa99 4 rpa011 5 then removing 'rpa' containing rows based on the first column years 1 bears 1 cats 2 thanks (7 Replies)
Discussion started by: phil_heath
7 Replies

6. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

7. Shell Programming and Scripting

deleting rows that dont have ....

Hi I posted earlier. This is sorta similar but I want to delete rows that dont have R, T, Y or U. Nam1 RTYU Nam2 RRTT Nam3 RYTU Nam4 IRTT So the output would look like this? Nam1 RTYU Nam2 RRTT Nam3 RYTU too many problems thanks (3 Replies)
Discussion started by: kylle345
3 Replies

8. Shell Programming and Scripting

Deleting rows from csv file

Hello, I am supposed to process about 100 csv files. But these files have some extra lines at the bottom of the file. these extra lines start with a header for each column and then some values below. These lines are actually a summary of the actual data and not supposed to be processed. These... (8 Replies)
Discussion started by: cobroraj
8 Replies

9. Shell Programming and Scripting

Deleting rows that begin with #

Hi, I have a file that has rows that start with # and ends with #. For example.. # hi text JK NM JK NM JK K JK NM # no # yes So I want to remove the #'s and put them into another file. so the output will be two files.. File 1: JK NM JK NM JK K JK NM (3 Replies)
Discussion started by: phil_heath
3 Replies

10. Shell Programming and Scripting

Deleting the emty rows in a file

I am getting some spaces between the two lines(rows) in file.i want delete that empty rows in the file example 1 abc xyz 2 def jkl like i am having lots of rows in a file i want to delete the spce between the two rows give any... (7 Replies)
Discussion started by: srivsn
7 Replies
Login or Register to Ask a Question