Csv file separate using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Csv file separate using awk
# 1  
Old 05-09-2014
Csv file separate using awk

Hi,

I have file like below

Code:
apple,orange,pineapple,pappya,guva,avocado

want to store as

Code:
apple
orange
pineapple
pappya

I tried below command to seprate first field

Code:
command1:
 
/usr/xpg4/bin/awk -F',' 'print {$1}' filename
 
command2:
 
/usr/xpg4/bin/awk 'BEGIN {FS=',';} print{$1}' filename

but I am getting error, both are not working
# 2  
Old 05-09-2014
Code:
awk '{n=split ($0,tab,",")}END{for(i=0;i<=n;i++)print tab[i]}' filename

# 3  
Old 05-09-2014
Code:
awk '1' RS=',' file

# 4  
Old 05-09-2014
Quote:
Originally Posted by stew
Hi,

I have file like below

Code:
apple,orange,pineapple,pappya,guva,avocado

want to store as

Code:
apple
orange
pineapple
pappya

I tried below command to seprate first field

Code:
command1:
 
/usr/xpg4/bin/awk -F',' 'print {$1}' filename
 
command2:
 
/usr/xpg4/bin/awk 'BEGIN {FS=',';} print{$1}' filename

but I am getting error, both are not working
Hi stew,
Do you really just want to print the 1st four fields?

What error messages are you getting?
Quote:
Originally Posted by protocomm
Code:
awk '{n=split ($0,tab,",")}END{for(i=0;i<=n;i++)print tab[i]}' filename

Hi protocomm,
Assuming that stew isn't using a Solaris system and wants to print all fields (instead of just the first four shown as the desired output), the following would be simpler:
Code:
awk -F, '{for(i = 1; i <= NF; i++) print $i}' filename

This User Gave Thanks to Don Cragun For This Post:
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 Dump data into CSV file which is Separate by <tab>?

Dear Team, please help me to solve this problem using Linux command. I want to dump this data into an excel sheet, Suppose I have a string like: ABC PQR XYZ ASD then I expect output as a ABC XYZ PQR ASD (3 Replies)
Discussion started by: Shubham1182
3 Replies

2. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

How to separate data coming in one column of CSV file?

I am running an ISQL command on Sybase DB and getting output of a query in an CSV file. The issue is that all the data comes in to the same column, i want them to be separated in different columns. SQL_COMMAND=command.sql file=file.txt formatFile=formatFile.txt report=report.csv echo... (1 Reply)
Discussion started by: Sharma331
1 Replies

4. UNIX for Dummies Questions & Answers

Writing multiple outputs in to separate cells of CSV file

Hi I am writing a script which has multiple awk statements and each statement gives me a numeric count as an output. I want those output to be stored in different cells of a csv file. say 12 awk statements give 12 output and i want them in diffrenet cells of csv file. Thank you guys..!! (4 Replies)
Discussion started by: prabhat.diwaker
4 Replies

5. Shell Programming and Scripting

Need help with awk statement to break nth column in csv file into 3 separate columns

Hello Members, I have a csv file in the format below. Need help with awk statement to break nth column into 3 separate columns and export the changes to new file. input file --> file.csv cat file.csv|less "product/fruit/mango","location/asia/india","type/alphonso" need output in... (2 Replies)
Discussion started by: awk-admirer
2 Replies

6. UNIX for Dummies Questions & Answers

using sed delete a line from csv file based on specific data in two separate fields

Hello, :wall: I have a 12 column csv file. I wish to delete the entire line if column 7 = hello and column 12 = goodbye. I have tried everything that I can find in all of my ref books. I know this does not work /^*,*,*,*,*,*,"hello",*,*,*,*,"goodbye"/d Any ideas? Thanks Please... (2 Replies)
Discussion started by: Chris Eagleson
2 Replies

7. Shell Programming and Scripting

Awk variable in a separate file

Hi all, I have a requirement to put all the varibles used in an awk command in a separate file. This is because i have arround 100 variables used in an awk command. So i want to put all the variables used for the awk command in a separate file. Please help me on this. Thanks in adv. (6 Replies)
Discussion started by: gani_85
6 Replies

8. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

9. Shell Programming and Scripting

How to create a CSV File by reading fields from separate files

SHELL SCRIPT Hi, I have 3 separate files within a folder. Every File contains data in a single column like File1 contains data mayank sushant dheeraj File2 contains DSA_AT MG_AT FLAT_09 File3 contains data 123123 232323 (2 Replies)
Discussion started by: mayanksargoch
2 Replies

10. Shell Programming and Scripting

handling multiple files using awk command and wants to get separate out file for each

hai all I am new to the world of shell scripting I wanted to extract two columns from multiple files say around 25 files and i wanted to get the separate outfile for each input file tired using the following command to extract two columns from 25 files awk... (2 Replies)
Discussion started by: hema dhevi
2 Replies
Login or Register to Ask a Question