Want to remove the last characters from each row of csv using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to remove the last characters from each row of csv using shell script
# 8  
Old 12-02-2011
@rajak.net: Don't you have Perl installed on your system? Or you haven't checked my solution yet?
# 9  
Old 12-02-2011
Quote:
Originally Posted by balajesuri
@rajak.net: Don't you have Perl installed on your system? Or you haven't checked my solution yet?
Hi balajesuri,

thanks for your solution. This may work for my first query but later I've corrected my issue. Actually I'm trying to remove some of the fields from csv which creates the '|' symbols in the next line instead of in the same line. Can you please check my corrected post and please help on that.
# 10  
Old 12-02-2011
What result do you get with gawk?
# 11  
Old 12-02-2011
Quote:
Originally Posted by CarloM
What result do you get with gawk?
Hi CarloM,

My CSV file:
Code:
HRLOAD|Service|AddChange|EN
PERSONID|STATUS|LASTNAME|FIRSTNAME|ITDCLIENTUSERID|ADDRESSLINE1
10000001|ACTIVE|Testazar1|Testore1|20041|
10000002|ACTIVE|Testazar2|Testore2|20042|Street East

I tried to delete the ITDCLIENTUSERID field using the following script:
Code:
awk 'BEGIN { FS="|"; OFS="|" } {$5="";$5=$6;$6=""}1' test.csv >> new6;

which gives the output like this:
Code:
HRLOAD|Service|AddChange|EN
PERSONID|STATUS|LASTNAME|FIRSTNAME|ITDCLIENTUSERID|ADDRESSLINE1
10000001|ACTIVE|Testazar1|Testore1
||
10000002|ACTIVE|Testazar2|Testore2|Street East
|

Expected result should be:
Code:
HRLOAD|Service|AddChange|EN
PERSONID|STATUS|LASTNAME|FIRSTNAME|ITDCLIENTUSERID|ADDRESSLINE1
10000001|ACTIVE|Testazar1|Testore1||
10000002|ACTIVE|Testazar2|Testore2|Street East|

Thanks in Advance.

Moderator's Comments:
Mod Comment Please use code tags
# 12  
Old 12-02-2011
Quote:
Originally Posted by rajak.net
awk
Quote:
Originally Posted by CarloM
What result do you get with gawk?
That wasn't a typo Smilie.

gawk and awk are different on AIX (as far as I remember).
# 13  
Old 12-02-2011
There is no gawk on AIX (at least not by default).

awk and nawk are the same.

The awk as given works fine for me. The input file must have an issue.
# 14  
Old 12-02-2011
Quote:
Originally Posted by rajak.net
My OS is AIX.
I'm not ftping the file from windows. It is with in the same server i.e. AIX server. Any help?

thanks in advance.

Please post the output of the following commands (for couple of lines at least).
Code:
od -c file
cat -v file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

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. 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... (3 Replies)
Discussion started by: Samah
3 Replies

3. Shell Programming and Scripting

Shell script that should remove unnecessary commas between double quotes in CSV file

i have data as below 123,"paul phiri",paul@yahoo.com,"po.box 23, BT","Eco Bank,Blantyre,Malawi" i need an output to be 123,"paul phiri",paul@yahoo.com,"po.box 23 BT","Eco Bank Blantyre Malawi" (5 Replies)
Discussion started by: mathias23
5 Replies

4. 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

5. Shell Programming and Scripting

Remove ^? characters in shell variables on using backspace

Friends, I observed a peculiar problem in shell. if I set a variable using standard input and backspace was used by the user, then the variable get ^? characters embedded in the variable. ### echo "Enter value for X=" read X echo $X expr $X + 1 ### If the variable is echoed, then there... (3 Replies)
Discussion started by: sachinverma
3 Replies

6. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

7. 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

8. Shell Programming and Scripting

remove row if string is same as previous row

I have data like: Blue Apple 6 Red Apple 7 Yellow Apple 8 Green Banana 2 Purple Banana 8 Orange Pear 11 What I want to do is if $2 in a row is the same as $2 in the previous row remove that row. An identical $2 may exist more than one time. So the out file would look like: Blue... (4 Replies)
Discussion started by: dcfargo
4 Replies

9. Shell Programming and Scripting

Blank Space is not appending in each row of CSV File - Shell Script

I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces. In my SQL script,the last column is like below. RPAD(' ',23,' ') -- Padding 23 blank Spaces The CSV file is generated but the sapce(23 spaces) is... (2 Replies)
Discussion started by: praka
2 Replies

10. Shell Programming and Scripting

Script to find and remove characters

Hi. I have many files in a folder, and even more in the subfolders. I need a script that finds and removes certain characters (them being /n in this one) in the files in the folder and it's subfolders. So, could someone write me a script that works in Linux, does this: Searchs for "/n" in... (5 Replies)
Discussion started by: Zerby
5 Replies
Login or Register to Ask a Question