Help with script printing column with space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with script printing column with space
# 1  
Old 12-16-2007
Help with script printing column with space

I am having some issues with a script taking in column #5 which has a space and splitting it into another line. I don't want this but I can not figure out why its doing this. Any help is appreciated.


Here is my input file (comma delimited):

Vendor_ext_AltMfg_6.6.6.6,host,6.6.6.6,255.255.255.255,olive drab,EOC

Here is my script:

#!/bin/bash
#
# ------>>>>> This assumes that the hosts.csv file is comma delimited <<<<<-------
#


for i in `cat drab.txt`; do
name=`echo $i | awk -F, '{ print $1 }'`
ip=`echo $i | awk -F, '{ print $3 }'`
mask=`echo $i | awk -F, '{ print $4 }'`
color=`echo $i | awk -F, '{ print $5 }'`

echo "create host_plain $name" >> /fwlogs/dbedit/dbedit_add_hosts_script.txt

echo "modify network_objects $name ipaddr $ip" >> /fwlogs/dbedit/dbedit_add_hosts_script.txt

echo "modify network_objects $name color $color" >> /fwlogs/dbedit/dbedit_add_hosts_script.txt

echo "update network_objects $name" >> /fwlogs/dbedit/dbedit_add_hosts_script.txt

done

echo "quit -update_all" >> /fwlogs/dbedit/dbedit_add_hosts_script.txt

Here is the output I get where the column #5 with the space gets split into another line:

create host_plain Vendor_ext_AltMfg_6.6.6.6
modify network_objects Vendor_ext_AltMfg_6.6.6.6 ipaddr 6.6.6.6
modify network_objects Vendor_ext_AltMfg_6.6.6.6 color olive
update network_objects Vendor_ext_AltMfg_6.6.6.6
create host_plain drab
modify network_objects drab ipaddr
modify network_objects drab color
update network_objects drab
quit -update_all
# 2  
Old 12-16-2007
Code:
#!/bin/sh

echo "Vendor_ext_AltMfg_6.6.6.6,host,6.6.6.6,255.255.255.255,olive drab,EOC" | (
IFS=,
while read A B C D E F G H
do
   echo A=$A
   echo B=$B
   echo C=$C
   echo D=$D
   echo E=$E
   echo F=$F
done
)

# 3  
Old 12-16-2007
Thanks for the quick reply. I don't know how to get your solution working with multiple lines.

how do I use that with multiple input lines in the input file? I want to parse the input file to make a text file formated in my above original script?

Vendor_1_1.1.1.1,host,1.1.1.1,255.255.255.255,olive drab,EOC
Vendor_2_2.2.2.2,host,2.2.2.2,255.255.255.255,green,EOC
Vendor_3_3.3.3.3,host,3.3.3.3,255.255.255.255,blue,EOC
Vendor_4_4.4.4.4,host,4.4.4.4,255.255.255.255,black,EOC
Vendor_5_5.5.5.5,host,5.5.5.5,255.255.255.255,white,EOC
Vendor_6_6.6.6.6,host,6.6.6.6,255.255.255.255,orange,EOC
# 4  
Old 12-16-2007
Code:
#!/bin/sh

IFS=,
export IFS
while read A B C D E F G H
do
   echo A=$A
   echo B=$B
   echo C=$C
   echo D=$D
   echo E=$E
   echo F=$F
done <<EOF
Vendor_1_1.1.1.1,host,1.1.1.1,255.255.255.255,olive drab,EOC
Vendor_2_2.2.2.2,host,2.2.2.2,255.255.255.255,green,EOC
Vendor_3_3.3.3.3,host,3.3.3.3,255.255.255.255,blue,EOC
Vendor_4_4.4.4.4,host,4.4.4.4,255.255.255.255,black,EOC
Vendor_5_5.5.5.5,host,5.5.5.5,255.255.255.255,white,EOC
Vendor_6_6.6.6.6,host,6.6.6.6,255.255.255.255,orange,EOC 
EOF

# 5  
Old 12-16-2007
works great!!! Thanks for the quick help!! Much appreciated!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent column printing

Hi, I have a file that has inconsistently numbered columns. Like row1 has 23 columns, and row 2 has 34 columns etc. I would like to re-order the first 8 columns as required and from the 9th column till the end, I would like to print it as it is. I tried to read the re-ordered 8 columns... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

2. UNIX for Dummies Questions & Answers

Printing out lines that have the same value in the first column but different value in the second

Hi, I have a text file that looks like the following: ILMN_1343291 6 74341083 74341772 ILMN_1343291 6 74341195 74341099 ILMN_1343295 12 6387581 6387650 ILMN_1651209 1 1657001 1657050 ILMN_1651209 5 83524260 83524309 I... (1 Reply)
Discussion started by: evelibertine
1 Replies

3. Shell Programming and Scripting

printing certain elelment of a column

"File1.txt" CHR SNP BP ANNOT 8 rs1878374 127974042 MYC(-843.5kb)|FAM84B(+334.4kb) 2 rs2042077 16883103 VSNL1(-702.2kb)|SMC6(-825.5kb)|RAD51AP2(-672.4kb)|MYCN(+878.5kb)|MSGN1(-978.2kb)|GEN1(-915.6kb)|FAM49A(+172.5kb) 12 rs10431347 3023955... (4 Replies)
Discussion started by: johnkim0806
4 Replies

4. Shell Programming and Scripting

Column printing in awk

Experts, i have a following file containing data in following manner. 1 2480434.4 885618.6 0.00 1948.00 40.00 1952.00 ... (6 Replies)
Discussion started by: Amit.saini333
6 Replies

5. UNIX for Dummies Questions & Answers

Printing a particular column using SED

Hi, i want to display only the particular column using SED command. For example, ps -ef|grep ash |sed -n '1p'|cut -d ' ' -f2   this gives 29067 ps -ef|grep ash |sed -n '1p'|awk '{print $2}'    this also gives the same  in the same way i need the solution using sed. Please... (4 Replies)
Discussion started by: pandeesh
4 Replies

6. Solaris

Printing a particular column[autosys]

Dear All, I'm using autosys in my production system. My concern is as follows: autosys -j <some_job_nm> Output: Job Name Last Start Last End ST Run Pri/Xit ... (1 Reply)
Discussion started by: saps19
1 Replies

7. Shell Programming and Scripting

printing space after a record in awk

friends, I am running iostat command in linux. Following is the output iostat -d Linux 2.6.18-128.el5 (btovm725.ind.hp.com) 04/16/2010 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 21.49 5.32 255.61 2871221 138010414 sda1 ... (8 Replies)
Discussion started by: achak01
8 Replies

8. UNIX for Dummies Questions & Answers

creating a file using the fist column and printing second column

Hello all. I have a problem that I need help solving. I would like to convert the following file: human pool1_12 10e-02 45 67 human pool1_1899 10e-01 45 29 human pool1_1829 10e-01 43 26 horse pool1_343 10e-20 65 191 horse pool1_454 10e-09 44 43... (5 Replies)
Discussion started by: viralnerd
5 Replies

9. UNIX for Dummies Questions & Answers

Help required on printing the line if third field is not a empty space

Hi Experts, I want to print the lines whose third field in non-empty/blank space. i.e. INPUT FILE/B] dcdccghjrry0yd cont dcdccttrk820529 cont rdekedfsSCr dcdccttrdky2d0y cont rdekedfsSC2 ... (3 Replies)
Discussion started by: krao
3 Replies

10. Shell Programming and Scripting

regarding about printing row to column

Hello, I got data like that, =111 A= alpha B= 1 C= qq D= 45 F= ss G= 334 =1234 A= B= 2w C= D= 443 F= G= =3434 A= B= e3e (5 Replies)
Discussion started by: davidkhan
5 Replies
Login or Register to Ask a Question