Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to take input from two files in a UNIX script? Post 302780411 by Corona688 on Thursday 14th of March 2013 01:13:40 PM
Old 03-14-2013
Same file with delimiters:

Code:
while IFS="," read VAR1 VAR2 THEREST
do
        ...
done < inputfile

Two files:

Code:
exec 5<file1 # Open file into FD 5
exec 6<file2

while read VAR1 <&5 && read VAR2 <&6
do
        ...
done

exec 5<&- # Close FD 5
exec 6<&-

One file would obviously be preferable.

Also, you don't need to reopen Results.txt 9,000 times to write 9,000 lines to it. You can redirect the output of your loop the same way you redirect its input.

Code:
while ...
do
...
done > results.txt

This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find files on a given input date

Hello gurus, I need to write a script to find out all the file that got changed on a specific folder since a given input date (Date to be given as Input) Thanx (1 Reply)
Discussion started by: ar.karan
1 Replies

2. Shell Programming and Scripting

Write a new file from 2 files as input to the script

Hi- I am hoping someone can give me some pointers to get me started. I have a file which contains some dn's .e.g file 1 cn=bob,cn=user,dc=com cn=kev,cn=user,dc=com cn=john,cn=user,dc=com I have a second file e.g. file.template which looks something like :- dn: <dn> objectclass:... (5 Replies)
Discussion started by: sniper57
5 Replies

3. Shell Programming and Scripting

How to get this script work on multiple input files

Hello Gyues! I would like to use awk to perform data extraction from several files. The data files look like this: DWT26R 1 PEP1 CA 1 OH2 SKIPPED: 0 STEP: 1 0.29000E+01 0.55005E-02 0.60012E-03 0.30000E+01 0.11149E+00 0.13603E-01 0.31000E+01 0.39719E+00 0.63013E-01 0.32000E+01... (9 Replies)
Discussion started by: Daniel8472
9 Replies

4. Shell Programming and Scripting

How to Process input files from folder in shell script?

Hi, I want to process all input files available into folder (C:\ShellPrg\InputFile\) Input files are abc.CSV , XYZ.zip (zip of CSV file), PQR.gz (zip of CSV file). I want to check the extension of file, If its .zip/.gz then need to unzip the file as .CSV I want to parse line by line of... (2 Replies)
Discussion started by: Poonamol
2 Replies

5. Shell Programming and Scripting

Perl Script Not Reading Input Files Correctly

This is one of the strangest things that's happening to me. I'm writing a new Perl script that is trying to read a file. The file is originally in .mof format, but I also saved the contents into a .txt file. As a simple test, I wrote this: #!/user/bin/perl -w use strict; ... (3 Replies)
Discussion started by: kooshi
3 Replies

6. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

7. Shell Programming and Scripting

Help in unix script to join similar lines of input

Hi, I have been thinking of how to script this but i have no clue at all.. Could someone please help me out or give me some idea on this? I would like to group those lines with the same first variable in each line, joining the 2nd variables with commas. Let's say i have the following input. ... (3 Replies)
Discussion started by: rei125
3 Replies

8. Shell Programming and Scripting

Standardization of input source data files using shell script

Hi there, I'm a newbie in unix and am fishing for options related to how raw input data files are handled. The scenario, as I'm sure y'all must be very familiar with, is this : we receive upwards of 50 data files in ASCII format from various source systems - now each file has its own structure... (3 Replies)
Discussion started by: Prat Khos
3 Replies

9. Shell Programming and Scripting

Building a dynamic UNIX menu with input files

Hi! I am looking to build dynamic menu (named: lookup.sh) that reads a pipe delimited file for input. for example, contents of input.txt could be: user1|srv1 user3|srv1 user4|srv1 user2|srv2 I want the menu look like: 1) get password for user1 on srv1 2) get password for user3 on... (7 Replies)
Discussion started by: cpolikowsky
7 Replies
ICONV(1)							 Debian GNU/Linux							  ICONV(1)

NAME
iconv - Convert encoding of given files from one encoding to another SYNOPSIS
iconv -f encoding [-t encoding] [inputfile]... DESCRIPTION
The iconv program converts the encoding of characters in inputfile, or from the standard input if no filename is specified, from one coded character set to another. The result is written to standard output unless otherwise specified by the --output option. --from-code, -f encoding Convert characters from encoding. --to-code, -t encoding Convert characters to encoding. If not specified the encoding corresponding to the current locale is used. --list, -l List known coded character sets. -c Omit invalid characters from output. --output, -o file Specify output file (instead of stdout). --silent, -s Suppress warnings, but not errors. --verbose Print progress information. --help, -? Give help list. --usage Give a short usage message. --version, -V Print program version. ENCODINGS
The values permitted for --from-code and --to-code can be listed by the iconv --list command, and all combinations of the listed values are supported. Furthermore the following two suffixes are supported: //TRANSLIT When the string "//TRANSLIT" is appended to --to-code, transliteration is activated. This means that when a character cannot be represented in the target character set, it can be approximated through one or several similarly looking characters. //IGNORE When the string "//IGNORE" is appended to --to-code, characters that cannot be represented in the target character set will be silently discarded. AUTHOR
iconv was written by Ulrich Drepper as part of the GNU C Library. This man page was written by Joel Klecker <espy@debian.org>, for the Debian GNU/Linux system. 3rd Berkeley Distribution lenny ICONV(1)
All times are GMT -4. The time now is 06:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy