Solved

Need proper formatting for outputing text data to Excel

Posted on 2015-02-24
1
69 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 13

Accepted Solution

by:
Mark Bullock earned 500 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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

623 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