| | |
Help in shell Script(REmove lines from file)
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
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
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
0
#2 32 Days Ago
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/bash # # cat 2.txt | while read LINE do BUF="`grep \`echo ${LINE} | awk '{ print $1 }'\` 1.txt`" if test $? -eq 0 then echo ${BUF} else echo ${LINE} fi done
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:
Kind regards,
issue9
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)
#!/bin/bash # # cat 2.txt | while read LINE do if test "" = "${LINE}" then echo "" else BUF="`grep \`echo ${LINE} | awk '{ print $1 }'\` 1.txt`" if test $? -eq 0 then echo ${BUF} else echo ${LINE} fi fi done > buf.txt mv buf.txt > 1.txt
Kind regards,
issue9
![]() |
Similar Threads
- how to remove a number of lines from a text file ? (Python)
- Replace text in a file (Shell Scripting)
- c++ or shell script to delete some files (C++)
- Problem with variables in Windows shell script (Windows NT / 2000 / XP)
- Why my shell script doesn't delete a file ?? (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: Using user input in BASH array.
- Next Thread: access time of a file in unix
Views: 12679 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





