Sponsored Content
Top Forums Shell Programming and Scripting Help to process line by line and assign value to variables Post 302695763 by cwzkevin on Monday 3rd of September 2012 07:20:25 PM
Old 09-03-2012
Thanks, Jim
There might be a typo, but the follow code works:
Code:
while read line; do
   declare -a arr=($line)

   start=${arr[4]}
   end=${arr[5]}
   id=${arr[[10]}
   ...
done < inputfile

Quote:
Originally Posted by jim mcnamara
Code:
while read myline
do
   # make every word
   declare -a ( $myline )  # works with tab or space by default

   start=${arr[4]}
   end=${arr[5]}
   id=${arr[[10]}

done < inputfile

 

10 More Discussions You Might Find Interesting

1. Programming

how do u assign the values to different variables when it is presneted in one line??

hey people.. i have a configuration file that looks like 7080 7988 net04.xxxxx.edu 20 where 20 is the number of threads in the thread pool initially. net04.xxxxx.edu is the hostname. and 7080 7988 are two ports. first one for client requests and second one for dns communication. now my... (2 Replies)
Discussion started by: SwetaShah
2 Replies

2. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

3. UNIX for Dummies Questions & Answers

shell script to process file line by line

Hi , I am new to shell scripting (ksh shell) and trying to accomplish few requiremtns. I have a file with the following format EMP NO EMP NAME AGE Amt Paid 12 Mark Taylor 32 32333 14 James Brown... (5 Replies)
Discussion started by: royalsing
5 Replies

4. Shell Programming and Scripting

Assign Line Numbers to each line of the file

Hi! I'm trying to assign line numbers to each line of the file for example consider the following.. The contents of the input file are hello how are you? I'm fine. How about you? I'm trying to get the following output.. 1 hello how are you? 2 I'm fine. 3 How about you? ... (8 Replies)
Discussion started by: abk07
8 Replies

5. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

6. Shell Programming and Scripting

linux shell script to take variables from two different files line by line

Friends I need to have a shell script which will feed variables from two different files line-by-line. For example, I have two files - permission and file_name. Contents of permission is - 644 755 .... contents of file_name /file1 /file2 ..... Now I want 644 permission will be... (4 Replies)
Discussion started by: atanubanerji
4 Replies

7. 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

8. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

9. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

10. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies
read(1) 						      General Commands Manual							   read(1)

NAME
read - read a line from standard input SYNOPSIS
var ... DESCRIPTION
reads a single line from standard input. The line is split into fields as when processed by the shell (refer to shells in the first field is assigned to the first variable var, the second field to the second variable var, and so forth. If there are more fields than there are specified var operands, the remaining fields and their intervening separators are assigned to the last var. If there are more vars than fields, the remaining vars are set to empty strings. The setting of variables specified by the var operands affect the current shell execution environment. Standard input to can be redirected from a text file. Since affects the current shell execution environment, it is usually provided as a normal shell special (built-in) command. Thus, if it is called in a subshell or separate utility execution environment similar to the following, it does not affect the shell variables in the caller's environment: Options recognizes the following options: Do not treat a backslash character in any special way. Consider each backslash to be part of the input line. Opperands recognizes the following operands: var The name of an existing or nonexisting shell variable. EXTERNAL INFLUENCES
Environment Variables determines the internal field separators used to delimit fields. RETURN VALUE
exits with one of the following values: 0 Successful completion. >0 End-of-file was detected or an error occurred. EXAMPLES
Print 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 SEE ALSO
csh(1), ksh(1), sh(1), sh-posix(1). STANDARDS CONFORMANCE
read(1)
All times are GMT -4. The time now is 02:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy