Need a piece of shell scripting to remove column from a csv file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a piece of shell scripting to remove column from a csv file
# 1  
Old 06-06-2016
Need a piece of shell scripting to remove column from a csv file

Hi,

I need to remove first column from a csv file and i can do this by using below command.

Code:
cut -f1 -d, --complement Mytest.csv

I need to implement this in shell scripting, Whenever i am using the above command alone in command line it is working fine.

I have 5 files in my directory and i need to find this file and then need to remove the first column from the file and i have to use the updated file which doesn't contain the removed column for later use in the script.

I tried few ways but no luck, its is just displaying the data which is there in Mytest.csv.

Thanks in advance.

Samah



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 06-06-2016 at 02:19 PM.. Reason: Added code tags.
# 2  
Old 06-06-2016
Please show us your "few ways" so we can analyze and point out why and where they fail.

EDIT:
When you say
Quote:
i need to find this file
how do you identify it? What makes it stand out from the others?
# 3  
Old 06-06-2016
Where are you sending the output to your cut command. Output from commands will typically go to your std out device, most often your screen. That is, unless you redirect your output.

What is the rest of your script?
# 4  
Old 06-07-2016
I have tried below piece of codes so far
1.
Code:
FILE="Mytest.csv"

if [ -f "$FILE" ];
then
cut -f1 -d, "Mytest.csv`
   echo " FILE UPDATED "
else
   echo "File $FILE does not exist" 
fi

2.
Code:
FILE="Mytest.csv"

if [ -f "$FILE" ];
then
cut -f1 -d, "Mytest.csv`
   echo " FILE exist | `cut -f1 -d, Mytest.csv` "
else
   echo "File $FILE does not exist" 
fi

Thanks,
Samah

Last edited by Don Cragun; 06-07-2016 at 05:01 AM.. Reason: Add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

2. Shell Programming and Scripting

How to calculate avg values of csv file using shell scripting .?

hi all i have a reporting work and i want it to be automated using shell scripting kindly let me know how can i make that possibe . eg data are :... (2 Replies)
Discussion started by: Avinash shaw
2 Replies

3. Shell Programming and Scripting

Remove the values from a certain column without deleting the Column name in a .CSV file

(14 Replies)
Discussion started by: dhruuv369
14 Replies

4. Shell Programming and Scripting

Shell scripting:from text file to CSV

Hello friends, I have a file as follows: "empty line" content1 content2 content3 content1 content2 content3 content1 content2 content3 It starts with an empty line, how can i get a csv like this: (12 Replies)
Discussion started by: kraterions
12 Replies

5. Shell Programming and Scripting

Remove line breaks in csv file using shell script

Hi All, I've a csv file in which the record is getting break into 1 line or more than one line. I want to combine those splits into one line and remove the unwanted character existing in the record i.e. double quote symbol ("). The line gets break only when the record contains double... (4 Replies)
Discussion started by: rajak.net
4 Replies

6. Shell Programming and Scripting

How to insert a sequence number column inside a pipe delimited csv file using shell scripting?

Hi All, I need a shell script which could insert a sequence number column inside a dat file(pipe delimited). I have the dat file similar to the one as shown below.. |A|B|C||D|E |F|G|H||I|J |K|L|M||N|O |P|Q|R||S|T As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies

7. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

8. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

9. Shell Programming and Scripting

shell script to remove extra commas from CSV outp file

Name,,,,,,,,,,,,,,,,,,,,Domain,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Contact,Phone,Email,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Location -----------------------,------------------------------------------------,-------,-----,---------------------------------,------------------------------------ ----... (1 Reply)
Discussion started by: sreenath1037
1 Replies
Login or Register to Ask a Question