ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Also, be sure to quote the variables so that it will work if they have spaces:
Code:
provision "$uname" "$pass" displayName "$name"
Because if the name varaible contains, for example "John Doe", then if not for the double quotes, bash will split it into two arguments, "John" and "Doe".
Note: The (NR>1) will skip the first record (line) in the file -- it means the bit in braces will only be run for the second and further records. If you do not have a header line, just omit that bit.
You can obviously add further checks.
Note that your output format may lead to problems if any of the fields (address, password, or full name) contain spaces. Perhaps you can add quotes. I separated each with a tab, since the original data uses that as a separator and therefore the fields cannot contain tabs.
If provision is a shell command, or uses standard quoting rules, I recommend you use
The \047 in the snippet above are just single quotes. The parameters to the provision command will be in single quotes, with single quotes properly escaped (by the gsub commands).
I tested this with a dummy provision command and some example data (including ' and spaces), and it works for me.
Seems odd that wc -c would return a count of +1 than the actual number of characters. Counting a whitespace or something?
No, it is counting the '\n' at the end due to the echo. try using '-n' option.
Also, in case you are interested, you could do it all in awk:
Code:
awk -F'\t' 'length($2) < 6{<do your magic here for less than 6 characters>}{cmd = "provision "$1" "$2" displayName \047"$3"\047"; print | cmd}' /opt/tmp/test.tsv
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.