0

I need delete lines with pattern similar, in multiple files (2500 .in files). example I have an input file -- "transmission-gtk.in" -- whose content is something like, but it is variable, I do not know:

#!/bin/sh
Popcon=18013
Section=main
Name='<b>Transmission</b>'
Comment='<span size="xx-large">Download and share files over BitTorrent</b>'
Name='<b>Start Transmission with All Torrents Paused</b>'
Name='<b>Start Transmission Minimized</b>'
Comment3=' '
License=' '
Screenshot=' '

In the above case "transmission-gtk.in" I need automatic delete:

Name='<b>Start Transmission with All Torrents Paused</b>'
Name='<b>Start Transmission Minimized</b>'

I have tried this, but it doesn't work in my case:

cd $HOME/My_files_in

PATH_WITH_SLASH=`sort *.in | uniq -D -w 10` 
for i in $PATH_WITH_SLASH; do sed -i "\|$PATH_WITH_SLASH|d" $i ; done

The result said: "The argument list is too long"
davidva
  • 160
  • Do the files you're looping through have any spaces in their names? – slm Mar 01 '14 at 02:03
  • The sed doesn't look right to me either. You're replacing in sed -i ... using the same variable that you're using for the source of dirs. in the for i in .... What's going on there? – slm Mar 01 '14 at 02:07
  • @slm I need use the same file but if I don't have alternative is welcome, the names don't has spaces; sorry my english is bad. – davidva Mar 01 '14 at 03:06
  • Your English is fine to me! – slm Mar 01 '14 at 03:17

1 Answers1

0

This is really just a guess since this question really isn't clear. Hopefully reading this will help you to clarify (if its not right). First to see a list of the files this will operate on, you can do:

 find dir/with/files -name '*.in'

Once you are happy you have the right files:

find dir/with/files -name '*.in' -print0 |
  xargs -0 sed "
    \:Name='<b>Start Transmission with All Torrents Paused</b>': d;
    \:Name='<b>Start Transmission Minimized</b>': d"

This will print a concatenation of the files with the lines you require removed gone. This may print a lot of data if there are a lot of files or they are long files. You can CtrlC to cancel.

If you are happy it is doing what you want, add the -i option to sed to actually modify the files. If it is not what you want, then the only way to recover will be from a backup.

find dir/with/files -name '*.in' -print0 |
  xargs -0 sed -i "
    \:Name='<b>Start Transmission with All Torrents Paused</b>': d;
    \:Name='<b>Start Transmission Minimized</b>': d"
Graeme
  • 34,027