Deleting of Specific Rows.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting of Specific Rows.
# 8  
Old 01-10-2010
Quote:
Originally Posted by gregarion
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?
Reading and writing to the same file in a single command is not possible.
# 9  
Old 01-10-2010
Okay, i solved that problem. what i am doing now is that i want to do a check to make sure that they are getting the information from the right row.

T
Code:
itle=
Price=
price_check=
echo -n "Title:"
read Title  
echo -n "Price:"
read Price
price_check = grep $Title fruit | grep $Price | awk -F":" '{print $3}' -line10
read price_check
if [$price_value = $Price] ; then

echo "Found the following record that matched:"

but i got an error message which reads

Code:
./delete: line 10: price_check: command not found

i was trying to put the value which i read into price_check. how else can i go about?
# 10  
Old 01-10-2010
There's two things wrong with your price_check assignment statement.

1. Remove or comment out "-line10". This isn't understood by the shell

Code:
price_check = grep $Title fruit | grep $Price | awk -F":" '{print $3}' #-line10

2. Whenever you need to execute a command and use the results, you will need to use backticks (`)

Code:
price_check = `grep $Title fruit | grep $Price | awk -F":" '{print $3}'`

Once you make these changes it should run better.

You will also not need the read statement after it, and $price_value will need to be $price_check

Code:
#read price_check
if [$price_check = $Price] ; then

# 11  
Old 01-10-2010
Code:
./delete: line 10: price_check: command not found
./delete: line 11: [: =: unary operator expected

i got this errors when i corrected my mistakes.


Code:
Title=
Price=
price_check=
echo -n "Title:"
read Title  
echo -n "Price:"
read Price
price_check = `grep $Title fruit | grep $Price | awk -F":" '{print $3}'`
if [$price_check = $Price ] ; then

echo "Found the following record that matched:"
 # grep $Title filename | grep $Price
fi

# 12  
Old 01-10-2010
Code:
if [ "$price_check" = "$Price" ] ; then

There needs to be a space between [ and $ and using double quotes around the variables is a good idea.
# 13  
Old 01-10-2010
Yeap, i did do that earlier but the same error which is ,
Code:
./delete: line 10: price_check: command not found

just keep appearing. Is the value of the price_check being read at all?
# 14  
Old 01-10-2010
Hello gregarion.

You also have spaces here:
Code:
price_check = ...

Remove the spaces either side of the equal sign.

Code:
price_check=`grep $Title fruit | grep $Price | awk -F":" '{print $3}'`

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