Combine two lists of variables


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Combine two lists of variables
# 8  
Old 06-16-2015
Quote:
Originally Posted by Corona688
That has no * in line 6 either. That can't be what you did.

Without seeing your actual input, I'll extrapolate from your broken program instead:

Code:
set -- ANUP ANVA ANYA ANZH ARMU BELA CAWI CHAZ CHJO CHSC CHSH CRSW DAHA DIWE DOWI ELBU GLGO HOCH JASH JEAM JERE JOWR JYAK KABL KAGI KARO KRAR LAFR LATE LICR MAGE MEWE MILE MIWA NALU NYSH NYWE PAMA SATI SHCO SHME STAL SWPA TAGR TIKI UZOM

for x in 1712 1922 2001 1700 1743 1860 2017 1838 2190 1750 1973 1909 2075 1843 1906 2103 1957 1813 1888 1961 1893 1772 2038 1957 1959 2055 2036 1903 1775 1839 2144 2322 1844 1855 1722 1731 1722 2038 1788 1856 1949 1837 1864 1847 1831
do
        echo "$1" "$x"
        shift 1
done

Feel free to post your actual input, so I can do what you actually want.
This worked-many thanks!
# 9  
Old 06-16-2015
If you have bash-3 or higher you can use arrays:
Code:
A=(
ANUP ANVA ANYA ANZH ARMU BELA CAWI CHAZ CHJO CHSC CHSH CRSW DAHA DIWE DOWI ELBU GLGO HOCH JASH JEAM JERE JOWR JYAK KABL KAGI KARO KRAR LAFR LATE LICR MAGE MEWE MILE MIWA NALU NYSH NYWE PAMA SATI SHCO SHME STAL SWPA TAGR TIKI UZOM
)
B=(
1712 1922 2001 1700 1743 1860 2017 1838 2190 1750 1973 1909 2075 1843 1906 2103 1957 1813 1888 1961 1893 1772 2038 1957 1959 2055 2036 1903 1775 1839 2144 2322 1844 1855 1722 1731 1722 2038 1788 1856 1949 1837 1864 1847 1831
)
afields=${#A[@]}
i=0
while [ $i -lt $afields ]
do
  echo "${A[$i]} ${B[$i]}"
  ((i++))
done


Last edited by MadeInGermany; 06-16-2015 at 03:11 PM.. Reason: don't need $(())
# 10  
Old 06-16-2015
Try also
Code:
A="ANUP ANVA ANYA ANZH ARMU BELA CAWI CHAZ CHJO CHSC CHSH CRSW DAHA DIWE DOWI ELBU GLGO HOCH JASH JEAM JERE JOWR JYAK KABL KAGI KARO KRAR LAFR LATE LICR MAGE MEWE MILE MIWA NALU NYSH NYWE PAMA SATI SHCO SHME STAL SWPA TAGR TIKI UZOM"
B="1712 1922 2001 1700 1743 1860 2017 1838 2190 1750 1973 1909 2075 1843  1906 2103 1957 1813 1888 1961 1893 1772 2038 1957 1959 2055 2036 1903  1775 1839 2144 2322 1844 1855 1722 1731 1722 2038 1788 1856 1949 1837  1864 1847 1831"
while [ ${A// } ]; do echo ${A%% *} ${B%% *}; A="${A#* } "; B=${B#* }; done
ANUP 1712
ANVA 1922
.
.
.

# 11  
Old 06-18-2015
Rudi, your solution needs exactly one space character between the elements.
For example 1843 1906 not 1843 1906.
Here is another solution that also works with older bash and ksh, and can be piped to a while loop for further processing.
Code:
paste <( printf "%s\n" \
ANUP  ANVA ANYA ANZH ARMU BELA CAWI CHAZ CHJO CHSC CHSH CRSW DAHA DIWE DOWI ELBU GLGO HOCH JASH JEAM JERE JOWR JYAK KABL KAGI KARO KRAR LAFR LATE LICR MAGE MEWE MILE MIWA NALU NYSH NYWE PAMA SATI SHCO SHME STAL SWPA TAGR TIKI UZOM
) <( printf "%s\n" \
1712 1922 2001 1700 1743 1860 2017 1838 2190 1750 1973 1909 2075 1843  1906 2103 1957 1813 1888 1961 1893 1772 2038 1957 1959 2055 2036 1903  1775 1839 2144 2322 1844 1855 1722 1731 1722 2038 1788 1856 1949 1837  1864 1847 1831
) | while read A B
do
  echo "$A $B"
done


Last edited by MadeInGermany; 06-18-2015 at 03:58 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

guide needed to combine 2 variables

readNOW=$(date +"%Y%m%d%H%M") read readTerminal #input B terminalc=$readTerminal echo eqpt_list_QC_$terminalcT_$readNOW how to get display result it: eqpt_list_QC_BT_201209121530 (2 Replies)
Discussion started by: ment0smintz
2 Replies

2. Shell Programming and Scripting

get the lists

I expert, I may cross post something similar but I dirtyed my quesion somehow to be clear in the thread #cat file1 88dee gcc: Grok for callconvention-hard to enable hard float a2ad2 eglibc: package mtrace separately 61487 python: bump PR of packages after update of distutils.bbclass... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

3. Shell Programming and Scripting

Using foreach with two lists

Hi everybody, I'm trying to use a foreach command with two lists. The file.txt looks like this: var1: 100 200 300 var2: 3 6 9 I'm trying to use a foreach command to associate the two variables together. My script looks like this: #! /bin/tcsh set a=(`cat file.txt | grep 'var1' | cut -d... (8 Replies)
Discussion started by: SimonWhite
8 Replies

4. Shell Programming and Scripting

Combine two lists From Multiple Grep commands.

I'm working with a file with an xml structure. I'd like to parse it down to just the bits i want. Here is and example of the file <message id="96352877" method="status"> <date rfc="Sat, 12 Mar 2011 16:13:15 -0600" unix="1299967995" /> <services> <service id="facebook"... (4 Replies)
Discussion started by: Erulisseuiin
4 Replies

5. UNIX for Dummies Questions & Answers

File Field Replacement, Assigning Fields to Variables, Lists/Arrays?

Okay, I've made threads on extracting fields and comparing strings in separate files in .csv's. I've written the following code with intentions of learning more. I just want this one question answered: How can I assign fields from a file(comma separated) to variables? My goal is to check... (0 Replies)
Discussion started by: chickeneaterguy
0 Replies

6. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

7. Shell Programming and Scripting

combine variables in one

Within one of my scripts, I have variables extracted from parameters list and want to combine some of them in one (lpath). I tried using awk command..... How do I get it? Thank you. #!/bin/bash # ## Read paramlist.txt file='/name1/name2/paramlist.txt' while read line do # key= echo... (4 Replies)
Discussion started by: Lenora2009
4 Replies

8. AIX

grep using lists?

I have a file that contain a list of files. How can I use grep to search the files in the list for a specific pattern? (2 Replies)
Discussion started by: bbbngowc
2 Replies

9. Shell Programming and Scripting

awk : combine 3 variables into 1

Within one of my awk scripts, I have three variables extracted and calculated on. When done, I simply want to combine the three. The following works, but looks weird. My script reads a field that has text and numbers, knowing the last four comprise MMYY (month and year) # YY are last two... (2 Replies)
Discussion started by: joeyg
2 Replies
Login or Register to Ask a Question