Know the current filename sed is processing and to inform it to shell
How to know the current filename sed is processing and to inform it to shell environment variable
Find in all .txt files line with NA end if any. If any then remove the line and quit with exit 0 (shell true), else exit any error code Code:
echo *.txt |xargs sed -Ei '/NA$/{d; q0}; q1 ' ..... Thanks. |
The echo is passing the literal string '*.txt' to xargs and it is sed itself which ends up globbing. So a very different approach is needed, if the above illustrated your model correctly. Also, the sed script you have truncates the files instead of just removing the first occurence of a line with the pattern.
Code:
for f in *.txt; |
From the sed manual:
Quote:
Code:
sed -Ei '/NA$/{F;s/.*/FOUND/;h;d;b};${x;s/^FOUND$//;x;t;q1}' *.txt |
The F function looks like the right choice, when it exists. However which version of Sed is it in? It's not in GNU sed 4.7, for example,
Code:
$ sed --version | sed '1q' |
SOLVED by @shruggy
|
@Turbocapitalist. The code for F was committed to GNU sed on 2009-11-15:
Quote:
|
Quote:
Code:
$ dpkg -S /bin/sed |
Well, manual pages for GNU tools are not authoritative. (Sometimes, they're even not from the upstream, but created by Debian maintainers.) You should look it up in the info manual.
|
Subjectively speaking, I've never found anything of use in the info "manuals", most of which are placeholders, and the interface for them is innavigable. Nothing good to say about them except that they seem to have died on the vine and are going away.
I'm disappointed that the manual pages are so neglected. They should be the penultimate authority, second only to the source code. |
I wish it were as you described. Unfortunately, citing the GNU Coding Standards:
Quote:
Quote:
|
Something else:
Code:
echo *.txt |xargs sed ... Code:
sed ... *.txt |
All times are GMT -5. The time now is 05:18 PM. |