Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning various lines from input file to a variable 1

Status
Not open for further replies.

hopwon

Technical User
Mar 7, 2007
6
ZA
Hi all,

I have a file in the format:

14B
0
10
37 - this is going to be converted to hex
03B1
03B2
03B3
03B4 etc,

I want to assign the first 4 lines each to a variable
v1 v2 v3 v4
Then process the rest of the file using the variables to get the output

map dev 03B1 to dir 14B:0, target=10, lun=25 (HEX 37)

So far I've got

awk -v t1=$target -v l1=$lun '{print"map dev "$1" to dir 14B:0, target="t1", lun
="$(NF+1)=sprintf ("%x",NR+l1)";"}0' /input/file;

What I want is the above awk command to extract the first 4 lines from /input/file and assign them to internal variables. Then I can compile this into a .exe

Thanks in advance

 
Something like this perhaps?

Code:
awk -v t1=$target -v l1=$lun '
    NR<4{v[NR]=$1}
    NR>4{print"map dev "$1" to dir "v[1]":"v[2]", target="t1", lun="$(NF+1)=sprintf ("%x",NR+l1)";"}0
' /input/file;

Not tested in any way...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top