Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need proper formatting for outputing text data to Excel

Posted on 2015-02-24
1
Medium Priority
?
74 Views
Last Modified: 2015-03-21
I am currently looping through files in a directory and outputting the file name, followed by 11 fields of relevant information.

Currently when I'm trying to output the data into a CSV file, its all in the same column (I need two columns)

#!/bin/bash

tmp_file=/tmp/test1_file.csv
> $tmp_file

for file in /home/jlefler/Desktop/EPA/*; do
   echo -e "${file##*/}\t\c" >> $tmp_file
   awk 'BEGIN{OFS="     "};{if (NF > 9) print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11}' $file >> $tmp_file
done

Open in new window


Suggestions would be very helpful.

To summarize, I need the CSV file to have two columns: the first column is the file name and the second column is several tab delimited files.
0
Comment
Question by:TampaJay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
Mark Bullock earned 2000 total points
ID: 40629183
Use the -v switch to pass in the environment variable. Then print its value and the comma at the beginning of each line.

Something like this:
awk -v myfile=$file 'BEGIN{OFS="     "};{if (NF > 9) print myfile, ",", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11}' $file >> $tmp_file

Open in new window

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question