Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Read line and save fields as variables Post 302979027 by Splinter479 on Monday 8th of August 2016 05:36:17 AM
Old 08-08-2016
thanks so far for your replies. I kind of have the feeling too that it is somehow related to the calls.txt
I thought the minimal example would do the job, but let's give you a more real copy of what I have done:

my.sh :
Code:
#!/bin/bash
echo " I AM OUTSIDE THE LOOP"

infile="calls.txt"

while IFS=',' read -r f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 f17 f18 f19
do
        echo " I AM INSIDE THE LOOP"

        my_file1=$f1
        species1=$f2
        chrom1=$f3
        my_file2=$f4
        species2=$f5
        chrom2=$f6
        binSize=$f7
        foo1=$f8
        foo2=$f9
        foo3=$f10
        foo4=$f11
        variance=$f12
        bar1=$f13
        bar2=$f14
        java_jar=$f15
        bar3=$f16
        bar4=$f17
        unit=$f18
        bar5=$f19

        # program calls here

done < "$infile"

my calls.txt is just a one liner right now, but later many lines according to the same format shall follow:
Code:
/path/to/my/file.txt,string1,string2,/path/to/my/other/file.txt,string3,string4,int1,string5,string6,int2,int3,int4,/path/to/a/third/file.txt,path/to/a/fourth/file.txt,/path/to/a/java.jar,anotherString,anotherString,anotherString,aFloatNumber

so this is exactly a renamed representation of the calls.txt. Sorry for the censorship, but in fact I am currently developing a software tool I am ofc not allowed to share everything in detail :/

I came up with the thoughts of maybe the paths messing it up? I 'll retry with quoting the paths. Other ideas?

EDIT: quoting didn't help :/
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read a line and put it into 3 variables

Hi All, I'll get a file whose 2nd line contains 3 fields: filename(variable length), file size char(10), and record count int(10). How do I cut it and put it into 3 variables? eg: abcd.csv01234567891111111111 now I want: $one = abcd.csv, $two = 0123456789, $three = 1111111111. I also... (8 Replies)
Discussion started by: Mandab
8 Replies

2. Shell Programming and Scripting

Read variables from line to fixed length

I would like to make a script to read three variables (no fixed length or position) from a line and write them into a file, with fixed length and right-justified in each column. The fixed text (text1-text4) prior to the thee variables and the variables themselves are originally separated by spaces... (3 Replies)
Discussion started by: SharkM
3 Replies

3. Solaris

Save enviroment variables

I need to save my enviroment variables,specially the $PATH.When I put it on .cshrc at next reboot I lost the configuration.How can avoid this?Thanks (2 Replies)
Discussion started by: bgf0
2 Replies

4. Shell Programming and Scripting

Read 1-line file and separate into multiple variables

I have one line files with 17 records separated by a semi-colon. I need to create a variable from each record, which I can do via a separate awk for each one, but I know there has to be a better way. Along with pulling out the variable, I need to convert some url coding like a + to a space, etc.... (4 Replies)
Discussion started by: numele
4 Replies

5. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

6. Shell Programming and Scripting

awk (or other) script that assigns fields from a line to multiple variables

Hey all, Unfortunately I have only basic knowledge of awk and/or scripting. If I have a file with lines that can look similar to this: Name=line1 Arg1=valueA Arg2=valueB Arg3=valueC Name=line2 Arg1=valueD Name=line3 Arg1=valueE Arg3=valueF Name=line4 Arg2=valueG ... (4 Replies)
Discussion started by: Rike255
4 Replies

7. Shell Programming and Scripting

How to read a delimited string and assign fields to incremented variables?

How can I read a string delimited on spaces and assign the fields to incremented variables. For example: Given $exts= txt dat mov I want to read in $exts and have "txt" "dat" and "mov" assigned to incremented variables like $ext1, $ext2, etc. I would like to do this in a loop so that I can... (4 Replies)
Discussion started by: runit
4 Replies

8. UNIX for Dummies Questions & Answers

Set variables from fields in fields

Hi, This is my first post here and I am a newbie. :) I have a file that looks like this : Introduction:Intro_123.html Product definition:Prod_def.html System Setup:SSetup-64bit.html Setting up user accounts:Set_user_acc.html I tried to create a script that would output "The filename... (3 Replies)
Discussion started by: Joq
3 Replies

9. Shell Programming and Scripting

read line by line and calculate the co-presence of variables

Hey guyz, I have a table which shows the presence or absence of my variables (A,B,C,...) in my observations (1,2,3,...) * A B C ... 1 1 0 1 2 1 1 0 3 1 0 0 ... I want to calculate the co-presence of my variables. to have a table shows the pairwise presence of the variables (have... (1 Reply)
Discussion started by: @man
1 Replies

10. Shell Programming and Scripting

Psql output into array and read 2 fields into different variables

Hello Just edited the entry to make it easier to understand what i want How can i achieve this: GOAL: read 2 field from a table with PSQL result of this PSQL command is this INSTALLEDLANG=$(su - postgres -c "psql -A -t -q -c -d ${DBNAME} -t -c 'SELECT code, iso_code from res_lang'") ... (0 Replies)
Discussion started by: winston6071
0 Replies
read(1) 						      General Commands Manual							   read(1)

NAME
read - Reads a line from standard input SYNOPSIS
read [-r] var... STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: read: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Do not treat a backslash character in any special way. Consider each backslash to be part of the input line. Note The -r option is included to enable read to subsume the purpose of the obsolete line utility. OPERANDS
The name of an existing or non-existing shell variable. DESCRIPTION
The read utility reads a single line from standard input. By default, unless the -r option is specified, backslash () acts as an escape character. If standard input is a terminal device and the invoking shell is interactive, read prompts for a continuation line in the following cases: The shell reads an input line ending with a backslash, unless the -r option is specified. A here-document is not terminated after a newline character is entered. The line is split into fields as in the shell (see the sh(1) reference page); the first field is assigned to the first variable var, the second field to the second variable var, and so forth. If there are fewer var parameters specified than there are fields, the leftover fields and their intervening separators are assigned to the last var. If there are fewer fields than vars, the remaining vars are set to empty strings. The setting of variables specified by the var parameters affects the current shell execution environment. If read is called in a subshell or separate utility execution environment, such as one of the following, it does not affect the shell variables in the caller's environ- ment: (read foo) nohup read ... find . -exec read ... ; NOTES
The -r option is included to enable read to subsume the purpose of the obsolete line utility. RESTRICTIONS
The results are undefined if an end-of-file is detected following a backslash at the end of a line when -r is not specified. EXIT STATUS
The following exit values are returned: Successful completion. End-of-file was detected or an error occurred. EXAMPLES
The following command prints a file with the first field of each line moved to the end of the line: while read -r xx yy do printf "%s %s " "$yy" "$xx" done < input_file ENVIRONMENT VARIABLES
The following environment variables affect the execution of read: Determines the internal field separators used to delimit fields. Pro- vides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization variables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization vari- ables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale used to affect the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Provides the prompt string that an interactive shell will write to standard error when a line ending with a backslash is read and the -r option was not specified, or if a here-document is not terminated after a newline character is entered. SEE ALSO
Commands: line(1) Functions: fread(3) Standards: standards(5) read(1)
All times are GMT -4. The time now is 11:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy