read file column and paste it in command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read file column and paste it in command
# 1  
Old 04-07-2009
read file column and paste it in command

Hi Unix gurus

I have a file containing 2 coloumns. I would like to do a script which reads the lines and executes a command like this:

command <field1> parameters <field2> some more parameters

Please let me know how you would do this without AWK, SED or any other mini language (for special restrictions I cannot use AWK).

A bit off topic further question - how can you check the return code of an executed command (system command) within AWK? Does $? work there too?

Cheers
BearCheese
# 2  
Old 04-07-2009
sounds like home work can you post your effort on this??
# 3  
Old 04-07-2009
Hi,
thanks for your reply - no it's not a homework. I would like to create a script for SAP application that can be used for mass transportation.

To be more precise the command would like the following:
tp import <field1> client<field2> u2368

the script should be able to read the parameter file from where field1 (transport number) and field2 (target client) may be inserted into the above pattern an execute it.

So far I have something like this:

#!/bin/ksh
command_part1="tp import"
command_part2="client"
command_part3="u2368"

while read line
do
fullcommand=${command_part1}" "(here I should get field1)" "${command_part2}" "(here I should get field2)" "${command_part3}
`$fullcommand`
if ($? -gt 0); then exit 8
fi
done < filename.txt

the reason I don't want to use AWK is curiosity plus I need to check the return code of the last command. If I used AWK, I could more simply do the field separation and can use the system command to execute commands but I'm not sure how to check the return code within AWK (hence my second off topic question in my original post)

I would like to know is there any way apart from AWK or SED to split the $line string into two fields, where the field seperator is a space " ". It can be comma or whatever is more comfortable.

Cheers
BearCheese
# 4  
Old 04-07-2009
Change the way you read in the data from the file, read in as 2 variables rather than single line:
Code:
while read field1 field2

# 5  
Old 04-07-2009
Code:
while read first second; do
  "$command_part1" "$first" "$command_part2" "$second" "$command_part3" ||
    exit 8
done < filename.txt

# 6  
Old 04-07-2009
Thanks guys!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. Shell Programming and Scripting

Paste 2 single column files to a single file

Hi, I have 2 csv/txt files with single columns. I am trying to merge them using paste, but its not working.. output3.csv: flowerbomb everlon-jewelry sofft steve-madden dolce-gabbana-watchoutput2.csv: http://www1.abc.com/cms/slp/2/Flowerbomb http://www1.abc.com/cms/slp/2/Everlon-Jewelry... (5 Replies)
Discussion started by: ajayakunuri
5 Replies

3. Shell Programming and Scripting

Problems with awk (fatal error) and paste (two variables into one column-by-column)

Hello, I have a script extracting columns of useful numbers from a data file, and manipulating the numbers with awk commands. I have problems with my script... 1. There are two lines assigning numbers to $BaseForAveraging. If I use the commented line (the first one) and let the second one... (9 Replies)
Discussion started by: vgbraymond
9 Replies

4. UNIX for Dummies Questions & Answers

Paste column from one file as column of

Any shortcuts for doing this? I need to cut the column 4 values from File1 and paste them as column4 values of File2, but only for the (first) same number of lines as File1 . All rows in File1 are contained in File2 in the exact same order, so the cut paste should work. File1 (with header and 3... (4 Replies)
Discussion started by: senhia83
4 Replies

5. Shell Programming and Scripting

How to make the cut command read a column after logical statements are meet?

Hi, I want to write a code that will cut everything that is under a couple of columns in a text file but so far I am not even close to achieve something like that. Basically, I want to cut all the information from the columns and transfer the column information to a spread sheet. I have... (1 Reply)
Discussion started by: pericopericone
1 Replies

6. Shell Programming and Scripting

Use of the PASTE command in a script file

Hi, When I use the paste command in the terminal window it works fine, but when i try to use it in a bash script file i get errors. I'm not sure how to use the paste command in a bash script file. my paste command looks like this paste <( code1 ) <(code2) thanks (7 Replies)
Discussion started by: eboye
7 Replies

7. Shell Programming and Scripting

Using paste command every nth number of file

Hi, I want to use paste command in a loop that does it every 6 files. My sample files are like the ones below. 20010101.txt 20010106.txt 20010111.txt 20010116.txt 20010121.txt 20010126.txt 20010131.txt 20010205.txt 20010210.txt 20010215.txt 20010220.txt 20010225.txt 20010302.txt... (4 Replies)
Discussion started by: ida1215
4 Replies

8. Shell Programming and Scripting

awk read value from file and paste in other file

Hi, I'm working on a perl-awk loop combination and what I want to do is read in the first line of values.exp and pass that value to test1.exp; next, read in the second line of that file and pass that value to test2.exp. Which would mean: values.exp: 1.2 1.4 test1.exp 1 test2.exp... (10 Replies)
Discussion started by: tobias1234
10 Replies

9. Shell Programming and Scripting

Copy a column and paste to other file question

Please help me. This is simple, but urgent problem for me. :( I have a two files file1 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 ..... file2 11 12 13 14 15 11 12 13 14 15 11 12 13 14 15 ..... 1) I hope to make a new file, file 3, that consists of 2nd... (2 Replies)
Discussion started by: exsonic
2 Replies

10. Shell Programming and Scripting

paste each 10 lines of single column to several column

Hi, I need to paste each 10 lines of single column to several columns. Please, can anyone tell me how to write in awk? Input File: 22 34 36 12 17 19 15 11 89 99 56 38 29 (4 Replies)
Discussion started by: nica
4 Replies
Login or Register to Ask a Question