Know the current filename sed is processing and to inform it to shell
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 ' .....
but how to get the file name if the condition is true to be echoing it (elipsis means the required answer on continuation) and won't echo it if it's false ?
Thanks.
Last edited by BudiKusasi; 07-26-2020 at 05:10 AM.
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;
do;
sed -i.orig -E -n '/NA$/{s/.*/foo/;h;d};p;${g;/foo/{q0};q1}' $f;
echo $?;
done;
The -i option should usually be given a string to append to the file name so that the original files are kept. That way there is a backup copy in the event of a mistake. However there are other ways to backup the files, such as tar, too.
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:
6.9 Man Pages
In the GNU project, man pages are secondary. It is not necessary or expected for every GNU program to have a man page, but some of them do. It’s your choice whether to include a man page in your program.
When you make this decision, consider that supporting a man page requires continual effort each time the program is changed. The time you spend on the man page is time taken away from more useful work.
Each program, utility, and function should have an associated manual page included in the same package. It is suggested that all configuration files also have a manual page included as well. Manual pages for protocols and other auxiliary things are optional.
If no manual page is available, this is considered as a bug and should be reported to the Debian Bug Tracking System (the maintainer of the package is allowed to write this bug report themselves, if they so desire). Do not close the bug report until a proper man page is available.
You may forward a complaint about a missing man page to the upstream authors, and mark the bug as forwarded in the Debian bug tracking system. Even though the GNU Project do not in general consider the lack of a man page to be a bug, we do; if they tell you that they don’t consider it a bug you should leave the bug in our bug tracking system open anyway.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.