Context:
I have a random pin number generator script that reads a tab-delimited file containing a location and a count:
eg.,
It produces random PIN# in the amount specified by the number in the second column.
Currently, I read the file and execute the generator function as follows:
I could also do something like this:
Then:
Or ...I could source the file ....but ....
The script won't know the names or amount of parameters in the file.
The file will have stuff added to it over time.
I could chuck it into the script:
Then deal with the passed variables that way ...but why?
Is there a point or advantage to sourcing the file in this case?
Have I already arrived at the ideal ( or one of several ) solution?
$'\t' (which is equivalent to a single quoted tab) works fine, if your shell supports it. If not, a backslash followed by a literal tab character would also work. It's important that the tab be quoted (as in your dollar sign syntax, or with a backslash, or quotes), otherwise, assuming a default value of IFS (space, tab, newline), the shell would consume the tab during the field splitting and IFS would be set to a null string.
Typing a literal tab on the command line can be done by typing control-v followed by control-i, or control-v followed by the tab key. In a text editor, you may be able to simply type tab, depending on how it's configured. A simple \t would not work. To the shell, that's equivalent to a plain t.
Regards and thank you very much for the bits,
Alister
Using the default value of IFS (space, tab, newline) would fail if the branch name consists of more than one space-separated word. The first word would be assigned to b, and the rest of the city words plus the count would be assigned to c.
The original code uses a tab delimiter, so mine does as well.
Hi,
I downloaded source code file from The GNU website and changed the source code of ls.c file, added printf command to it. It worked fine. Then, I deleted the printf command, saved the file and ran the command 'make sudo && make install' closed the terminal and printf statement went away.
I... (1 Reply)
Hello, I have a file in the following format
id sample platform R1 R2 gene1 gene2 gene3
1 abc llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp asp
2 def llumina R1_001.fastq.gz R2_001.fastq.gz apoe prnpp
3 ghi llumina ... (3 Replies)
I've a file in linux with following text:
;ip address hostname put-location alt-put-location tftpserver
192.168.1.1 r01-lab1-net /mnt/nas1/fgbu/ /opt/fgbu/devicebackup 192.168.1.254Now I want to read these values and assign them to particular variables... (6 Replies)
Hello C specialists,
I'm trying to write a program to read out a binary configuration file produced by a router.
But the output of Name and Value is cryptic. What's going wrong?
The structure of the binary file is very simple:
struct nvram_tuple {
char *name;
char *value;
... (5 Replies)
Hi All,
I am trying to read a .csv file which has some 6 columns.
Eg: samp.csv
one, two, three, four
six, seven, eight, nine
I used the following code,
for line in `cat samp.csv`
do
echo "$line"
done
It displays every comma seperated values in each line like,
one,... (1 Reply)
i get a name from user first name : last name, in this format. Now i am saving this to a file. what i want is, I do not want to save any name if I already have one entry o that same name..what should i do
for example
user give robert fernandez
this will save in file as robert:fernandez.
if... (5 Replies)
Hi,
In a script i am having trouble joining a variable to a file. for, example I read input from user as a variable a or b or c or d etc and want to join those to different files...
or
if user press a then it will open somefile.txt
if user press b then it will open otherfile.txt
any idea (4 Replies)
Hi,
I have prepared a config file in which I am declaring the value for a country such as: COUNTRY=USA
Now I am trying to read the country from the config file and print a message based on the same. I have written the following code in a script and when executing the script I getting an error.
... (14 Replies)
Hi,
I'm trying to write a script that reads filenames from a file and use these filenames in a loop. The filenames are all on one line and the problem is that these filenames have wildcards like * and braces like in them.
Right now what I'm doing is something like this:
echo "reading from... (0 Replies)