Help in shell Script(REmove lines from file)

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 2
Reputation: contactnaveen is an unknown quantity at this point 
Solved Threads: 0
contactnaveen contactnaveen is offline Offline
Newbie Poster

Help in shell Script(REmove lines from file)

 
0
  #1
Oct 14th, 2005
I want a shell script program for this purpose and here is my requirement.

I have two files 1.txt and 2.txt

In 1.txt I have the following contents:

label.abcd.1 = asdfgf

label.abcd.2 = qwerqwe

label.abcd.3 = zczxvzx

label.abcd.4 = ;lkjj;l

label.abcd.5 = pupoiup

and in 2. txt I have the following contents

label.abcd.1 = poiuppoiu

label.abcd.3 = iouyiuy

label.abcd.5 = uizxuci

label.abcd.6 = kxkjckvjh

label.abcd.7 = l;kjlkjlj;

Note the contents in 1.txt and 2.txt....... label.abcd.2,4 is removed and label.abcd.6,7 is added newly in 2.txt, and note the righthand side of 1.txt and 2.txt are different.

Now i want the content in 1.txt shd be like this

label.abcd.1 = asdfgf

label.abcd.3 = zczxvzx

label.abcd.5 = pupoiup

label.abcd.6 = kxkjckvjh

label.abcd.7 = l;kjlkjlj;

[label.abcd.6,7 are added and label.abcd.2,4 are removed.] Please Note: The right hand side of label.abcd.1,3,5 are not modified.

This is my requirement. I hope i have not confused u.....

Thanx in advance
Regards,
Naveen. V
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 10
Reputation: issue9 is an unknown quantity at this point 
Solved Threads: 1
issue9's Avatar
issue9 issue9 is offline Offline
Newbie Poster
 
0
  #2
32 Days Ago
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. #
  3. #
  4.  
  5. cat 2.txt | while read LINE
  6. do
  7. BUF="`grep \`echo ${LINE} | awk '{ print $1 }'\` 1.txt`"
  8. if test $? -eq 0
  9. then
  10. echo ${BUF}
  11. else
  12. echo ${LINE}
  13. fi
  14. done
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 15
Reputation: whizkidash is an unknown quantity at this point 
Solved Threads: 0
whizkidash's Avatar
whizkidash whizkidash is offline Offline
Newbie Poster
 
0
  #3
31 Days Ago
Hell Friend!
The above script provided does not work..
Please see the output when i run the script


./mod.sh
label.abcd.1 = poiuppoiu

i have the 1.txt and 2.txt but when i do a cat on 1.txt
it has done nothing!

Thanks for your patience

regards
Whizkidash
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 10
Reputation: issue9 is an unknown quantity at this point 
Solved Threads: 1
issue9's Avatar
issue9 issue9 is offline Offline
Newbie Poster
 
0
  #4
30 Days Ago
Hello whizkidash,


thank you very much for testing!

You're totally right, I oversaw the empty lines in the input file[s].

May you try this one:
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. #
  3. #
  4.  
  5. cat 2.txt | while read LINE
  6. do
  7. if test "" = "${LINE}"
  8. then
  9. echo ""
  10. else
  11. BUF="`grep \`echo ${LINE} | awk '{ print $1 }'\` 1.txt`"
  12. if test $? -eq 0
  13. then
  14. echo ${BUF}
  15. else
  16. echo ${LINE}
  17. fi
  18. fi
  19. done > buf.txt
  20. mv buf.txt > 1.txt

Kind regards,
issue9
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 12679 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC