deleting the part of the file(overwrite) using start and end point


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting the part of the file(overwrite) using start and end point
# 22  
Old 12-15-2011
What is the if condition? may be we can work that out, that might be easy...

--ahamed
# 23  
Old 12-15-2011
okay wait.. let me paste the partial code here...

Code:
flag=0
while read linexT
do
                                                 len=${#linexT}
                                                 charlast=${linexT:$len-1:$len}
                                                charfirst=${linexT:0:1}
                                                 if [ "$charlast" = "," ]
                                                 then
                                                      line11=${linexT:0:$len-1}
                                                 else
                                                      line11=$linexT
                                                 fi
                                                 if [ "$charfirst" = ">" ]
                                                 then
                                                           
#                                               here somewhere inbetween i am checking whether 
if flag=0
then
                do someting here
fi
fi
 
                   if [[ "$charfirst" = "<" ]]
                                                 then
                                                         line11=${line11:2:$len}
                                                        echo "missing in second: $line11"
                                                        colname1=$( echo $line11 | awk -F\` '{print $2}' )
                                                       line333=`cat tablextract2.sql | grep -w -i $colname1`
                                                        grep -w -i $colname1 tablextract2.sql | while read line22 ; do
 if [[ `expr match "$line11" ".*PRIMARY KEY.*"` = "0" ]]  &&  [[ `expr match "$line22" ".*PRIMARY KEY.*"` = "0" ]] && [[ "$key1" != "KEY" ]] &&  [[ "$key2" != "KEY" ]] && [[ `expr match "$line11" ".*UNIQUE KEY.*"` = "0" ]]  &&  [[ `expr match "$line22" ".*UNIQUE KEY.*"` = "0" ]]
         then
                                if grep -i -q "auto_increment" <<<$line22
                                then
                                         insert_column "$table_name1" "PRIMARY KEY (\`$colname1\`)"
                                         modify "$table_name1" "$line22"
                                        flag=1
                                        echo "flag: $flag"
                                else
                                         modify "$table_name1" "$line22"
                                fi
fi
done
 
done < tmp.sql

---------- Post updated at 02:18 PM ---------- Previous update was at 02:14 PM ----------

and also how to close a duplicate thread...?
# 24  
Old 12-15-2011
One way is to make use of tmp files...
Code:
grep -w -i $colname1 tablextract2.sql > /tmp/tmp.$$
while read line; do
  echo "$line"
  flag=1
  echo "flag: $flag"
done < /tmp/tmp.$$
 
echo "flag: $flag"
 
rm -f /tmp/tmp.$$

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 25  
Old 12-15-2011
oh this will work i guess.. thanks :-)... but what is tmp.$$...?
# 26  
Old 12-15-2011
$$ is the process ID of the shell - often used to make (somewhat) unique filenames.
This User Gave Thanks to CarloM For This Post:
# 27  
Old 12-15-2011
oh okay got it :-) thanks
# 28  
Old 12-15-2011
Quote:
Originally Posted by ahamed101
This is a known issue with bash.
This is not an issue with bash. Once you understand that the pipe launches a subshell, it comes as obvious that the parent shell does not know what the subshell did to its variable.
This User Gave Thanks to mirni For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

2. Shell Programming and Scripting

How to perform a hexdump using dd from start point to end point?

hi, I would like to ask or is it possible to dump a hex using dd from starting point to end point just like the "xxd -s 512 -l 512 <bin file>" I know the redirect hexdump -C but i can't figure it out the combination options of dd. Hope someone can share their knowledge.. Thanks in... (3 Replies)
Discussion started by: jao_madn
3 Replies

3. UNIX for Dummies Questions & Answers

Deleting part of file names

My server got messed up and the names of my files were not completely processed. As results I ended up getting a bunch of files with the following names: I need to remove the underscore and everything before it. Thus, the files will be renamed to something like this: Any help will be greatly... (3 Replies)
Discussion started by: Xterra
3 Replies

4. Shell Programming and Scripting

deleting blank lines ONLY at the end of the file

Hi Guys, I have a quetion which was already discussed in the forum, but for some reason all approches suggested fail for me. I have a file which have blank lines at the body of the text as well as at the end. I need to delete ONLY blank lines at the end. Unfortunatly the approach below does not... (5 Replies)
Discussion started by: aoussenko
5 Replies

5. Shell Programming and Scripting

Grepping from a point in a file to the end of the file

does any one know how to turn the equivalent of this command: awk '/2011 John Doe 8344/,0' /tmp/ops.log | egrep -c "received request" to something that would use egrep instead of awk? What the awk command does is, it searches the ops.log file for "2011 John Doe 8344". When it finds it,... (4 Replies)
Discussion started by: SkySmart
4 Replies

6. Shell Programming and Scripting

deleting the lines at the end of the file.

I have a text file with two coulmn first column is just used in to show the line number, these line number are not there in the real file. I want to delete the line 16(in this file) here, even tough there is no data inside it . this empty line is causing me a problem by throwing me garbage... (12 Replies)
Discussion started by: shashi792
12 Replies

7. UNIX for Dummies Questions & Answers

deleting word from this point to end of file in VI

Hi All i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out? Kind regards Brian (4 Replies)
Discussion started by: brian112
4 Replies

8. UNIX for Advanced & Expert Users

Deleting end of line $ character in file

Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
Discussion started by: bwrynz1
3 Replies

9. UNIX Desktop Questions & Answers

Deleting Junks at the end of each line in a file

Is there any way to delete the Junk Characters(Invalid Characters like ^,',",),(,&,# etc.,) at the end of each record in a file? I want to do this using a single line script. Thanks to all in advance!!! (5 Replies)
Discussion started by: dave_nithis
5 Replies

10. Shell Programming and Scripting

Deleting end line spaces for along file

How can i clear all space characteres for a long file at the end of each line? (3 Replies)
Discussion started by: osymad
3 Replies
Login or Register to Ask a Question