Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
Have a file (infile.txt) with 500 records,
that consists of mail addresses with records
and ; as fields separators lika this:
;name1@gmail.com;
;name2@gmail.com;
The results should go to an outfile.txt
Tried to make a script that remove the
fields separators. It "should" be an easy
thing to get working, but it seems
impossibly for me to get the script working.
Have read manuals and testing for hours
but no luck. Really feel like a newbie.
I hope someone can write a small script
for me that do the work.
If it is simply removing the semi-colons, as mentioned sed will do fine, but so will awk.
Show us what you tried so we can help with learning gawk maybe.
There is a lot to learn, even in that snippet. That couldn't work, your results are from a prior attempt.
You certainly don't want to use "\r" (a teletype carriage return) as an output separator. That will generate plenty of angst if you have more than one output field.
If you have a field separator as first character, $1 will be null - hence your lack of expected output.
OFS and FS are known variables to gawk - if you set them, they need to be done outside the code block, or in a BEGIN block. Not using -v which is used to pass in shell variables.
The input file name must be the last argument, outside the quoted gawk program text.
Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.
Here is a solution to the pitfall in my last post (#9):
if the input file is empty then the variable total is not initialized, it will be treated as an empty string rather than a zero integer.
If you want to force a zero integer you can either initialize it
Code:
awk '
BEGIN {total=0}
{total += $6}
END {print total}
' Test_file.txt
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.